On Tue, Oct 20, 2009 at 12:28 PM, Peter Kopke Jr. <p...@kopkefruit.com>wrote:

> Hello,
>
> I have a web-based system that accesses a mysql database through DBI.
> Currently I make a new database connection for each web access. I would like
> to retain the connection and database handle rather than making a new
> connection with each web access. Is there a simple way to do this?
>

Something like this?

my $dbh;

# later

sub request {

   $dbh ||= DBI->connect_cached( @args, { private_pid => $$ } );

Or better would be to test if $$ != $saved_dbh_pid and set InactiveDestroy
on the old $dbh and then create a new $dbh.

Then wrap the request in eval block and rollback on errors.

Or maybe try this:

http://search.cpan.org/~dwheeler/DBIx-Connector-0.20/lib/DBIx/Connector.pm


-- 
Bill Moseley
mose...@hank.org

Reply via email to