Re: mod_perl/Apache::DBI
[prev]
[thread]
[next]
[Date index for 2005/04/06]
I had a similar problem but approached it in a different way.
Apache::DBI can tell when the handle goes stale IFF the DBD implements
the 'ping' method. The standard MySQL driver apparently does not
implement said method, but I found some pointers in the man page that
showed a simple way to implement one. So I placed the following code in
a .pm file and load it early in the startup.pl. This has solved all my
problems in that area.Hope it helps you.
-Vince
=pod
Apache::DBI caches database handles for re-use. It uses the DBI->ping method
to test whether the connection is alive. However, DBD::mysql does not
implement
the ping() method, and the default implementation returns 1. So after the
database connection idles out (default 8 hrs), everything breaks.
This adds a ping method to DBD::mysql that will return true only when the
database is really there.
=cut
# This code taken from the Apache::DBI man page ;) -VV
package DBD::mysql::db; # ====== DATABASE ======
use strict;
sub ping ($)
{
my ($dbh) = @_;
my $ret = 0;
eval {
local $SIG{__DIE__} = sub { return (0); };
local $SIG{__WARN__} = sub { return (0); };
# adapt the select statement to your database:
$ret = $dbh->do('select 1');
};
return ($@) ? 0 : $ret;
}
e-just@xxxxxxxxxxxx.xxx wrote:
>Hi,
>
>I am using CDBI in an application and we would like to run in a mod_perl environment. The only problem is is the database goes down for some reason or another even if its for a really short time the connection is lost and the only way to get it back is to restart the server. I tried the solution at the top of http://www.class-dbi.com/cgi-bin/wiki/index.cgi?UsingWithModPerl
>
>but I get this error :
>
>Can't locate object method "select_row" via package "DBI::st" looks like its happening at this line:
>
>my @row = $self->sql_Flesh(join ", ", @want)->select_row($self->id);
>
>
>Is there something that I am missing?
>
>Thanks!
>
>Eric
>
>
|
(message missing)
|