"be consistent" | |
PerlMonks |
Re: check if DBI is still connectedby EvanCarroll (Chaplain) |
on Oct 06, 2005 at 08:42 UTC ( [id://497852]=note: print w/replies, xml ) | Need Help?? |
See options $dbi->{'RaiseError'} and $dbi->{'PrintError'}, querrying on a dead database will always throw an error or a warning respectively. If you set RaiseError to 1, and set PrintError to 0 (default), and capture the error message from $DBI::stderr after an eval, you can run a regex to see if it matches that of a failed connection, if it fails, reconnect and try again. eval { $dbi = blah; $sth = blah }; if ($@ && $DBI::stderr =~ m/Bad Connection/) {reconnect and start again} Evan Carroll www.EvanCarroll.com
In Section
Seekers of Perl Wisdom
|
|