Using perl 10 + lastest dbi + mysql, how do I implement a 'reconnect' method?
(This is with mysql_auto_reconnect => 0, obviously.)
I want to do
..
# some code that might timeout the connection
..
$dbh->ensure_connected;
# some code that relies on being connected
or
..
# some code that might fiddle with connection settings (eg fk checking)
..
$dbh->reconnect;
# some code that relies on being connected
(If you have a working 'reconnect' then 'ensure_connected' is trivial.)
The problem is I don't know how to replace the _content_ of $dbh with the
value of a replacement dbh. At the moment I'm trying to get by with
$dbh = $dbh->reconnect;
which works to a degree, but is no use when inside a (third-party) module because it would rely on the caller of that module also using that clumsy construct on the outside.
If dbh was a simple hash- or array-based object, the solution becomes easy, but it isn't.
The fact that DBD::Mysql is able to implement 'mysql_auto_connect' gives me hope that there's a solution possible.
-Nic