jmo has asked for the wisdom of the Perl Monks concerning the following question:
And I want to use it like if it was DBI, except of course the original connect:package MyDBI; use strict; use DBI; use DBD::mysql; use vars qw(@ISA); @ISA = qw(DBI); sub connect { my $self = shift; my ($dsn, $uname, $passwd) = @_; my $this = $class->SUPER::connect($dsn, $uname, $passwd); $this->set_dsn ($dsn, $uname, $passwd); # so I can reconnect easily return $this; } package MyDBI::db; @MyDBI::db::ISA = qw(DBI::db); my ($_uname, $_passwd, $_dsn); sub set_dsn { my $this = shift; ($_dsn, $_uname, $_passwd) = @_; } sub reconnect { # somthing like MyDBI->connect ($_dsn, $_uname, $_passwd); # and then rerun prepare } package MyDBI::st; @MyDBI::st::ISA = qw(DBI::st); sub execute { my $this = shift; $this->SUPER::execute (@_); if ($this->errstr =~ /server has gone away/) { MyDBI::db->reconnect; # and then rerun execute with some sleep to avoid insane bahvio +ur } } 1;
Thanksuse MyDBI; my $dbh= MyDBI->connect (...); my $sth = $dbh->prepare ("select now()"); sleep (10); # while sleeping the db goes away $sth->execute; # at this point MyDBI is supposed to reconnect and reru +n prepare/execute
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Reconnecting to a mysqldb
by jbert (Priest) on Nov 07, 2006 at 10:54 UTC | |
by clinton (Priest) on Nov 07, 2006 at 11:32 UTC | |
by jmo (Sexton) on Nov 07, 2006 at 12:42 UTC | |
|
Re: Reconnecting to a mysqldb
by pajout (Curate) on Nov 07, 2006 at 14:40 UTC | |
|
Re: Reconnecting to a mysqldb
by perrin (Chancellor) on Nov 07, 2006 at 15:26 UTC | |
by jmo (Sexton) on Nov 07, 2006 at 16:26 UTC | |
by perrin (Chancellor) on Nov 07, 2006 at 16:59 UTC | |
|
Re: Reconnecting to a mysqldb
by graff (Chancellor) on Nov 08, 2006 at 02:39 UTC |