sedusedan has asked for the wisdom of the Perl Monks concerning the following question:

DBIx::AutoReconnect is out of the question, because it messes up commit/rollback/RaiseError. So I'm turning to DBIx::Roles::AutoReconnect. Tried it at two separate occassions and it doesn't seem to do the job as advertised: the script still dies if MySQL daemon is restarted during the runtime of the script. I'm wondering if I'm not using them correctly. The incantation couldn't be simple enough, just 'use DBIx::Roles qw(AutoReconnect)' and 'DBI->connect()' as usual.

So far my workaround is to create a function like this:

sub connect_to_mysql { state $dbh; if (!$dbh || !$dbh->ping) { $dbh = DBI->connect(...); } $dbh; }

and make all other functions get their database handle from this function. Works beautifully, but this won't work if MySQL daemon goes away in the middle of a function.

  • Comment on Has anyone used DBIx::Roles::AutoReconnect / DBIx::AutoReconnect successfully?
  • Download Code