Carping About DBI - When Things Go Wrong
(Page 5 of 10 )
No matter how good you are, you're bound to screw up sometime. And when it happens, you'll be glad that I told you about $DBI::errstr, used to display error messages when things go wrong.
# connect
my $dbh = DBI->connect("DBI:mysql:database=somedb;host=localhost", "me",
"me545658") || die "Can't connect: $DBI::errstr";
Additionally, you can also check the handle for errors during a query - as the following example demonstrates.
while(my $ref = $sth->fetchrow_hashref())
{
print "Name: $ref->{'Name'} Species: $ref->{'Species'} Age: $ref->{'Age'}
\n";
if($sth->err)
{
die "There was an error: $sth->errstr";
}
This article copyright Melonfire 2001. All rights reserved.Next: Speed Demon >>
More Perl Articles
More By Vikram Vaswani, (c) Melonfire