Re: Design Pattern to keep a connection opened?
John R Pierce <[email protected]>
| Newsgroups | gmane.comp.lang.perl.modules.dbi.general |
|---|---|
| Message-ID | <[email protected]> |
On 11/05/11 11:59 PM, Brandon Phelps wrote:
> sub get_database {
> if (defined($dbh) && $dbh->ping) {
> return $dbh;
> } else {
> $dbh = DBI->connect($DB_dsn, $DB_user, $DB_pass);
> return $dbh;
> }
> }
if $dbh is defined but doesn't ping, I suspect you should free it before
you reconnect it or you're probably leaking some memory.
and I still think you should be doing this in a db->do() wrapper, whcih
checks for connection related errors and does the reconnect there.
you're not doing any error checking now.
--
john r pierce N 37, W 122
santa cruz ca mid-left coast