On Friday 20 May 2005 4:27 pm, Octavian Rasnita wrote:
> In all the modules I have put something like:
>
> package Site::Module1;
>
> use strict;
> use Site::MySQL (); #The module that connects to MySQL
> my $dbh = Site::MySQL::dbh();

You are creating a closure when you use that $dbh in your subs.  This is very 
bad, for multiple reasons.  In addition to the problem you already see, this 
will prevent Apache::DBI from reconnecting if your MySQL connection times 
out.  It will also break the safety rollback handler which you would need if 
you ever decide to use transactions.

> What should I do?
>
> Put "use Site::MySQL" and "my $dbh = Site::MySQL::dbh()" inside of
> subroutines?

You only need the "use" once at the top, but you should put the call to get 
the dbh at the beginning of each sub.  Apache::DBI will intercept the connect 
calls and give you back a cached handle.

- Perrin

Reply via email to