kiat has asked for the wisdom of the Perl Monks concerning the following question:
I've a question regarding explicitly disconnecting from the database. The relevant code (simplified) looks like this:
Do I need to explicitly call disconnect within the subroutine bail_out when an error occurred while executing the SELECT query?use CGI qw(:cgi); use DBI; # sanitize() not shown my $username = sanitize(param('username')); my $dbh->connect(assuming_relevant_connection_params_are_here); my $sql = qq{ SELECT COUNT(*) FROM profiles WHERE username=? }; my $result = $sth->execute($username) or bail_out('Error executing SELECT'); $dbh->disconnect; # do something based on $result sub bail_out { my $msg = shift; # prints error in html exit(0); }
Thanks for reading this and hope someone can enlighten me.
update
Thanks to all for advising :) I've a clearer picture of the options available to me now.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl dbi disconnect question...
by Zaxo (Archbishop) on Jan 04, 2004 at 17:05 UTC | |
by kiat (Vicar) on Jan 05, 2004 at 01:00 UTC | |
by Zaxo (Archbishop) on Jan 05, 2004 at 01:16 UTC | |
by kiat (Vicar) on Jan 05, 2004 at 01:47 UTC | |
|
Re: Perl dbi disconnect question...
by jeffa (Bishop) on Jan 04, 2004 at 17:09 UTC | |
by kiat (Vicar) on Jan 05, 2004 at 01:17 UTC | |
by jeffa (Bishop) on Jan 05, 2004 at 15:55 UTC | |
|
Re: Perl dbi disconnect question...
by CountZero (Bishop) on Jan 04, 2004 at 17:06 UTC | |
|
Re: Perl dbi disconnect question...
by stvn (Monsignor) on Jan 04, 2004 at 18:13 UTC |