Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Simple DBI handle caching.

by kyle (Abbot)
on May 11, 2011 at 16:10 UTC ( #904196=note: print w/ replies, xml ) Need Help??


in reply to Simple DBI handle caching.

I guess that wasn't so bad.

use English '-no_match_vars'; sub dbh { state $dbh; state $dbh_pid; if ( defined $dbh_pid && $PROCESS_ID != $dbh_pid ) { my $child_dbh = $dbh->clone; $dbh->{InactiveDestroy} = 1; $dbh = $child_dbh; $dbh_pid = $PROCESS_ID; $L->debug( "cloned database connection in PID $dbh_pid" ); } if ( ! defined $dbh ) { my ($u,$p) = ('user',':)'); $dbh = DBI->connect( "dbi:Sybase:server=sql.example.com", $u, $p, { RaiseError => 1 }, ); $dbh->do( $initialization_stuff ); $dbh_pid = $PROCESS_ID; $L->debug( "made new database connection in PID $dbh_pid" ); } return $dbh; }


Comment on Re: Simple DBI handle caching.
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://904196]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2014-12-20 11:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (95 votes), past polls