July 2005
Intermediate to advanced
1032 pages
27h 10m
English
client1.pl didn't do any error checking at all. The error messages that you saw were produced by DBI or DBD::Pg, not by the script. For simple applications, it might be sufficient to let DBI handle errors, but in more complex cases, you probably want some other options.
Let's start by modifying the previous client so that it prints its own error message if something goes wrong. Listing 14.4 shows the resulting code.
1 #!/usr/bin/perl -W 2 # 3 # Filename: client2a.pl 4 # 5 6 use strict; 7 use DBI; 8 9 my $dbh = DBI->connect( "dbi:Pg:" ) 10 or die "Can't connect to PostgreSQL: $DBI::errstr ($DBI::err)\n"; 11 12 $dbh->disconnect(); |
This script detects connect() failures by examining the ...
Read now
Unlock full access