programming-examples/perl/Database/Error Diagnostic Variables.pl

20 lines
521 B
Perl
Raw Normal View History

2019-11-15 12:59:38 +01:00
use DBI;
$driver="DBI:mysql";
$database="sample_db";
$user="root";
$host="localhost";
$dbh=DBI->connect('dbi:mysql:sample_db','root','password',{
RaiseError => 1,
PrintError => 0,
}
) or die $DBI::errstr;
$sth=$dbh->prepare("SELECT name FROM Employee") or die "Can't prepare sql statement" . DBI->errstr;
$sth->execute();
while(my @val = $sth->fetchrow_array()){
print "name=$val[0]\n";
}
print $sth->rows," rows were retrieved.\n";
$sth->finish();
$dbh->disconnect();