I wanted to build an awesome place for people to discuss module specific issues, but I don't have any more time for this, and there are much better places to discuss Perl-related issues. I'd recommend asking your question on Stack Overflow or on Perl Monks.
If you are looking for a Perl tutorial or Perl-related news, I hope these links will serve you well.
Posted on 2009-07-20 13:01:59-07 by claude
DBD-mysql-4.012 not reconnecting.
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.
Direct Responses: 12994 | Write a response
Posted on 2010-10-13 23:10:49.532524-07 by deiveegaraja in response to 11190
Re: DBD-mysql-4.012 not reconnecting.
Try to execute this code.U ll get a good result.
#!/usr/bin/perl # use strict; use DBI; use DBD::mysql; my $dsn='DBI:mysql:training:10.101.1.1'; my $dbh = DBI->connect ($dsn,"training","training",{ RaiseError => 1, AutoCommit => 1}); die "Unable to connect to database : $Mysql::db_errstr\n" unless $dbh; $dbh->{mysql_auto_reconnec +t} = 1; for (my $i = 0; $i < 10; $i++) { warn scalar localtime, " auto_reconnect = $dbh->{mysql_auto_reconnect}.\n"; my $sql = qq{select Sno from NEW_FYS_DEIVEEGARAJA where Cost='349.99'}; my $sth = $dbh->prepare ($sql); $sth->execute (); while(my $a=$sth->fetchrow_array) { warn "name = $Sno\n"; sleep 1; } } warn "OK\n";
Direct Responses: Write a response