|
Hi,
I'm using DBD::mysql in mod_perl CGI scripts and the auto reconnect feature doesn't work, I always get the dreaded 'MySQL server has gone away' message. The following simple test script shows the problem :
----------------------------------
#!/usr/bin/perl
#
use strict;
use DBI;
use DBD::mysql;
#
my $dsn = "DBI:mysql:database=dinfo;host=localhost:mysql_server_prepare=1";
my $dbh = DBI->connect ($dsn, 'dinfo', 'password', { RaiseError => 1, AutoCommit => 1});
die "Unable to connect to database : $Mysql::db_errstr\n" unless $dbh;
$dbh->{mysql_auto_reconnect} = 1;
for (my $i = 0; $i < 10; $i++) {
warn scalar localtime, " auto_reconnect = $dbh->{mysql_auto_reconnect}.\n";
my $sql = qq{select nom from dinfo.sciper where sciper = '105640'};
my $sth = $dbh->prepare ($sql);
$sth->execute ();
my ($name) = $sth->fetchrow;
warn "name = $name\n";
sleep 15;
}
warn "OK\n";
---------------------------------
I launch it and restart the server after the first iteration :
Fri Jul 17 18:00:26 2009 auto_reconnect = 1.
name = LECOMMANDEUR
Fri Jul 17 18:00:41 2009 auto_reconnect = 1.
DBD::mysql::db prepare failed: MySQL server has gone away at ./testdb1 line 15.
DBD::mysql::db prepare failed: MySQL server has gone away at ./testdb1 line 15.
Am I forgetting something ?
Thanks for any hints.
Claude.
|