So you are not using any kind of ping at all now? And this works? If you just want to turn off ping completely, I think Apache::DBI has an option for this. But was not your problem that the connection broke and you wanted automatic reconnects? Your code does not seem to do that.
sub DESTROY {
my $self=shift;
if ($dbhobject) {
$dbhobject = undef;
}
}
I doubt that this DESTROY method is called ever. Your $dbhobject is not a blessed reference (just a plain hash ref containing the DBI handle), so this is not really OOP and $classname, $self and so on are a little confusing.
Update: Okay, maybe I misunderstood. This is the old code you were using (with Apache::DBI)? And it did not reconnect? If so, you were not using Apache::DBI correctly. You have to use "connect" to get a connection, and Apache::DBI will either make a really new connection or just return an alreay open connection. That is transparent to you. What you cannot do is cache the connection Apache::DBI give you in your own singleton object. You have to "connect" every time you want a connection:
So instead of
sub new {
my $classname = shift;
my $self={};
if ($dbhobject) {
$self=$dbhobject
} else {
$self = bless {};
my $dbh = DBI->connect("DBI:mysql:blah) or
die DBI::errstr;
$self->{"dbh"} = $dbh;
}
$self;
}
sub DBHOBJ {
return $dbhobject->{"dbh"};
}
use
use Apache::DBI;
sub DBHOBJ {
DBI->connect("DBI:mysql:blah) or
die DBI::errstr;
}
|