If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Perl and the DBI > How to implement reconnect method

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-01-11, 08:25
niczero niczero is offline
Registered User
 
Join Date: Jun 2011
Posts: 2
How to implement reconnect method

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
Reply With Quote
  #2 (permalink)  
Old 06-02-11, 04:18
niczero niczero is offline
Registered User
 
Join Date: Jun 2011
Posts: 2
Easy :- pass by ref

Bah! It's all easy and not specific to DBI. It's so long since I've taken advantage of perl's pass-by-reference, I had forgotten it was an option.
So to pass the caller a replacement dbh, I just need to update $_[0].
Reply With Quote
Reply

Tags
mysql, mysql_auto_reconnect, objectoriented, reconnect

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On