All,
 
I have a problem in that I want to check if a DBI connection is still active.
For this I have heard you can use ping. But From the documents I've found I see that ping is always set to return true for DBD::mysql. But DBD::Oracle has a ping routine defined which does a valid check. The problem is my custom DBI class needs to handle any backend database so it must be able to use it's own ping method whenever one isn't present in the DBD::$driver class.
 
So I defined my own subroutine (found on the web - and which very simlar to the DBD::Oracle->ping method) to accomplish the mysql ping:-
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;
    }
 
So the question I have is "How" do I insert the ping subroutine into my own custom DBI class which calls DBI and maintains the dbh connection.
 
The only way I can think of is for my class to have a list of database driver classes which need to use my own ping. And then I can only implement my ping on those classes only and all others call $dbh->ping.
 
Before I embark on this I just wanted to sanity check if anybody else can point out an alternative way to do this.
 
Regards
 
Marty
 
 
 

Reply via email to