On Tue, 2007-07-31 at 14:36 +0800, Ken Perl wrote: > OK, got it. Is it possible to use the same db connections in one > request? if yes, could you please show me how to implement this if a > cgi script calls many times other perl modules which requests db > connections to work. >
Yes it is, although I'm not sure about using it with straight CGI (ie not via ModPerl::Registry/PerlRun etc). The opening lines of Apache::DBI contain this: --------------------------------------- use constant MP2 => (exists $ENV{MOD_PERL_API_VERSION} && $ENV{MOD_PERL_API_VERSION} == 2) ? 1 : 0; BEGIN { if (MP2) { require mod_perl2; require Apache2::Module; require Apache2::ServerUtil; } elsif (defined $modperl::VERSION && $modperl::VERSION > 1 && $modperl::VERSION < 1.99) { require Apache; } } --------------------------------------- So I would assume that if you use Apache::DBI in a CGI script, it's not going to have the MOD_PERL* environment variables set, and so it will assume mod_perl version 1, and require Apache. However, I see no reason to load the Apache.pm module in your case - you don't need it. What you could do instead is to use DBI's connect_cached method, which provides similar functionality. I actually use this instead of Apache::DBI, even when running under mod_perl. In either case, the way to reuse connections is to ensure that your connect call is exactly the same. Even changing the order of parameters will force Apache::DBI / connect_cached to generate a new connection. Clint