Stas Bekman wrote:

Hill, Ronald wrote:

It's much simpler than that. You need two sentences:

1) under mod_perl, globals remember their values from the previous request, so you can cache the connection with:

$dbh ||= myconnect();
But Apache::DBI implements pinging (immediate or timing based) which is much superior to this. Some databases drop connection otherwise. Or consider the case where the database goes down and then all the $dbh becomes invalid. Apache::DBI would recover gracefully I think. But the above method wouldn't.


2) If you rdbms supports cached statement handles (which most do), you can use Apache::DBI which caches database connection without needing to change any of your code.
I am not aware of Apache::DBI caching statement handles. Are you sure that Apache::DBI does this?

Or is it a side effect of caching the database handle.

If it is the latter, then then caching with #1 above would not solve the problem. If it is the former, perhaps someone can add a global setup variable to Apache::DBI to turn this feature off.

eg

$Apache::DBI::statement_handle_caching = 0; # default = 1


But of course I agree that it's a good idea to mention this topic. I suggest that many other topics are to be mentioned but replace discussions with pointers to the relevant chapters of the mod_perl books and online documentation. So newbies, know what to look for. It's not obvious that database connections can be cached.

__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com





Reply via email to