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?
Thanks,
Peter
If you are using apache web server they simply do
use Apache::DBI;
rather than
use DBI;
and it will let your reuse session and connections for you
or a longer term approach could be found with
http://search.cpan.org/~mws/ResourcePool-1.0104/lib/ResourcePool.pod
Hmm, that helps with mod_perl, but not with CGIs (which are still
commonly used with Apache). FastCGI / mod_fastcgi can also profit from
persistent connections, but you have to manage them yourself.
Alexander
Hmm, has anybody tried Apache::BabyConnect?
I did a search on CPAN for 'persistent'.
--
Ron Savage
r...@savage.net.au
http://savage.net.au/index.html
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
mos...@hank.org