Re: mod_perl/Apache::DBI

[prev] [thread] [next] [Date index for 2005/04/06]

From: Vince Veselosky
Subject: Re: mod_perl/Apache::DBI
Date: 22:35 on 06 Apr 2005
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)

mod_perl/Apache::DBI
e-just 16:07 on 06 Apr 2005

Re: mod_perl/Apache::DBI
Perrin Harkins 18:41 on 06 Apr 2005

Re: mod_perl/Apache::DBI
Vince Veselosky 22:35 on 06 Apr 2005

Re: mod_perl/Apache::DBI
Andy Grundman 22:49 on 06 Apr 2005

Re: mod_perl/Apache::DBI
Perrin Harkins 22:53 on 06 Apr 2005

Re: mod_perl/Apache::DBI
Vince Veselosky 23:10 on 06 Apr 2005

Re: mod_perl/Apache::DBI
Perrin Harkins 23:25 on 06 Apr 2005

Re: mod_perl/Apache::DBI
Vincent E. Veselosky 01:05 on 07 Apr 2005

Re: mod_perl/Apache::DBI
=?ISO-8859-1?Q?Ask_Bj=F8rn_Hansen?= 02:12 on 07 Apr 2005

Generated at 14:42 on 11 Apr 2005 by mariachi v0.52