Without the extra ping (see the line following the XXX comment) this
program fails on the second "select ..." with 

"DBD::mysql::db selectrow_array failed: Lost connection to MySQL server during query 
at dbitest line 19."

Why do I need to ping twice?

I am using perl 5.6.1, DBI 1.21 and DBD::mysql 2.1011.

I also tried upgrading DBI to 1.32 and DBD::mysql to 2.1022; but it
didn't change anything.


 - ask


#!/usr/bin/perl -w
use strict;
use DBI;

my $dbh_cache;
sub db_open {
  ## XXX - add an extra ping so the second ping will work properly!
  #$dbh_cache and $dbh_cache->ping;
  return $dbh_cache if $dbh_cache and $dbh_cache->ping;
  return $dbh_cache = DBI->connect("dbi:mysql:cswwwdata;user=root")
}

my $dbh = db_open();
my $thread_id = $dbh->{'mysql_thread_id'};
my ($count) = $dbh->selectrow_array(q[select count(*) from cities]);
system(qq[mysqladmin -uroot kill $thread_id]);

$dbh = db_open();
($count) = $dbh->selectrow_array(q[select count(*) from cities]);

1;

-- 
ask bjoern hansen, http://www.askbjoernhansen.com/ !try; do();

Reply via email to