Difference between revisions of "Perl DBI Examples"

From PeformIQ Upgrade
Jump to navigation Jump to search
(New page: =Examples= <pre> #!/usr/bin/env perl use DBI; # Open the database my ($DSN,$dbh,$sth); $dbh = DBI->connect("dbi??={SQL Server};Server=$db_instance;Database=$db_name;UID=$db_user;PWD=$...)
 
 
Line 28: Line 28:
</pre>
</pre>


[[Category:Perl]]
[[Category:PERL]]
[[Category:Database]]
[[Category:Database]]

Latest revision as of 14:55, 4 December 2008

Examples

#!/usr/bin/env perl

use DBI;

# Open the database

my ($DSN,$dbh,$sth);

$dbh = DBI->connect("dbi??={SQL Server};Server=$db_instance;Database=$db_name;UID=$db_user;PWD=$db_pass") or croak "$DBI::errstr\n";

# Get the patch names & store them in @files

my (@rows,@files,$key,$value);
my $sql = "select patch from computervulnerability where detected=0";
$sth = $dbh->prepare($sql) or die "$DBI::errstr\n";
$sth->execute or die "$DBI::errstr\n";

while (@rows = $sth->fetchrow_array()) {
        push(@files,$rows[0]);
}

# Close the database

$dbh->disconnect;