in reply to DBI Question
MySQL server has gone away means that you're no longer connected to the server. Either you have disconnected (e.g. you've let your database handle go out of scope) or your server is dropping the connection on its end.
It's a problem you'll have to address by checking to see if the connection is alive and re-connecting as needed. One way to do this is using DBIx::Abstract:
If you're not going to use DBIx::Abstract, the same basic idea can be had from simple DBI:use DBIx::Abstract; my $dbx = DBIx::Abstract->connect(...); sub do_query { $dbx->ensure_connection; ## do the query; }
$dbh = DBI->connect(...); sub do_query { my $connect; eval { ($connect) = $dbh->selectrow_array('SELECT 1'); }; if ($@ || !$connect) { $dbh = DBI->connect(...) or die "Can't reconnect: $DBI::err"; + } ## do query. }
I do recommend DBIx::Abstract, though -- you can still get at the database handle from it, but it makes moving from MySQL to PostgresQL or Oracle a snap!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: DBI Question
by kings (Sexton) on Jun 17, 2008 at 03:01 UTC |