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;