logo       

Re: Same $dbh under different pids?: msg#00583

apache.mod-perl

Subject: Re: Same $dbh under different pids?

harm wrote:

Moi,

a quick question: is it possible to have the 'same' dbh across the apache
children even if you do your best not to?

This minimalistic handler:
use strict;
package Foo;
use Apache::DBI;
use DBI;
use Apache::Constants qw':common';

my $dbh;

You haven't initialised this, so each request will get the same object that is made below.

$Apache::DBI::DEBUG = 1;

This should be in a start up file really.


sub handler {
my $r = shift;
$r->send_http_header;
$r->print("ok");

You could just put,
print "ok";

$dbh ||= DBI->connect("dbi:mysql: ... etc);

Apache::DBI takes care of pooling connections.
Use,

my $dbh = DBI->connect(@CONNECT);

and get rid of the global $dbh above.

Richard





<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise