in reply to Re: Perl dbi disconnect question...
in thread Perl dbi disconnect question...
With the settings above, does it mean that I don't need a 'or' to catch a failed query. See code below:my $dbh = DBI->connect( 'DBI:driver:database:host', 'user', 'pass', {RaiseError => 1, HandleError => \&bail_out}, );
Relatedly, do I need to explicitly call disconnect within bail_out with your settings (i.e. RaiseError => 1 and HandleError => \&bail_out)?my $dbh = DBI->connect( 'DBI:driver:database:host', 'user', 'pass', {RaiseError => 1, HandleError => \&bail_out}, ); my $sql = qq{ SELECT COUNT(*) FROM profiles WHERE username=? }; # Original #my $result = $sth->execute($username) # or bail_out('Error executing SELECT'); # Modified # Note that 'or' clause is removed my $result = $sth->execute($username); $dbh->disconnect;
That is:
Thanks for your great help :)sub bail_out { my $dbh = shift; $dbh->disconnect or bail_out(msg => "Cannot disconnect from the database"); # prints html message exit(0); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
3Re: Perl dbi disconnect question...
by jeffa (Bishop) on Jan 05, 2004 at 15:55 UTC |