Perl DBI Examples

From PeformIQ Upgrade
Jump to navigation Jump to search

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;