in reply to Reconnecting to a mysqldb
package MyProject::Database; use DBI; our $dbh; sub getDbh { #you should catch the exceptions and try to reconnect here if ($dbh) { $dbh->ping(); } else { $dbh = DBI->connect(); } return $dbh; } sub doSQL { my $dbh = getDbh(); return $dbh->do(@_); } sub query2aref { my $dbh = getDbh(); return $dbh->selectall_arrayref(@_); } 1;
Of course, for some reasons it is better to implement it as object instance, there is many ways how to do it...
|
|---|