On Monday 24 November 2003 03:49 pm, Perrin Harkins wrote:
> On Mon, 2003-11-24 at 15:35, Jordan Lederman wrote:
> > > You just have to look at the code you run from httpd.conf and
> > > startup.pl to see if it opens any connections.  The code you posted
> > > looks fine, but what's in Q2::Init?
> >
> >      25 $Apache::DBI::DEBUG = 2;
> >      26
> >      27 my $dbh = DBI->connect("dbi:Pg:dbname=queue", "queued","",
> > { AutoCommit=> 1, RaiseError => 1, PrintError
> >
> >         > 1 } ) or die "Cannot connect to db: $DBI::errstr \n";
>
> Is that inside a sub, or just in the main section of the module?  If
> it's in the main part of the module, can you remove it and connect
> later?
>

The my $dbh line above is located at the beginning of the file. When I copy it 
to the beginning of the sub all is fixed!. This leaves me a little puzzled. 
Since I need to use the dbh at many different points in my module, I figured 
declaring it at the top would be the way to go.  Since I am obvoisly wrong, 
where is the proper place for this line? Should it be decarled just inside of 
the sub handler { ..} sub? Should I declare one for each sub that will 
connect to the db (and if so, do I need to do any cleanup, ->finish, 
->disconnect ...). What is the best/proper solution?
                        --jordan
        

> > I am a bit confused on why I need to connect to the db both in startup.pl
> > and in my module. Can you shed any light on this?
>
> Your connect_on_init() in startup.pl tells Apache::DBI you want it to
> create a connection when it spawns child processes.  However, to access
> a cached connection in your module, you call DBI->connect and
> Apache::DBI intercepts that and hands you back a cached connection if
> there is one.
>
> - Perrin


-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html

Reply via email to