At 07:18 PM 8/1/2001 -0700, Nick Tonkin wrote:

>On Wed, 1 Aug 2001, Philip Mak wrote:
>
> > I have a CGI application where I do:
> >
> > require 'db.pl';
> >
> > where db.pl defines some functions and variables related to connecting to
> > the database, and then executes C<$dbh = DBI->connect(...)>.
> >
> > I tried to convert this application to modperl, but I ran into the problem
> > that require did not execute db.pl again the second time I called the
> > script, so that the C<$dbh = DBI->connect(...)> line was not executed.
> >
> > I can get around this by changing C<require> to C<do>, but is that the
> > "correct" way of doing things? It seems a waste to redefine all the
> > subroutines and variables again. But I do need it to reinitialize $dbh
> > when C<require 'db.pl';> is called.
> >
> > What should I do?
>
>
>One of the things you should do that I have not yet seen mentioned is
>look into using Apache::DBI so you don't have it "reinitialize $dbh" on
>every request.
>
>If you do have multiple DBs in your application you can still used cached
>database handles; just name them differently.

But you should still call $dbh = connect() on every request so that 
Apache::DBI's magic can truly work??

Otherwise ping tests and other such stuff will not work and you may as well 
not use Apache::DBI at all and just use BEGIN { $dbh ||= connect() } which 
of course, is probably not working well.



Reply via email to