$dbh->ping() not pinging?

$dbh->ping() not pinging?

Post by Ask Bjoern Hans » Sun, 05 Jan 2003 17:30:10



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")

Quote:}

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();

 
 
 

$dbh->ping() not pinging?

Post by Michael A Cha » Mon, 06 Jan 2003 00:20:58



Quote:

> 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.

I don't know a specific answer, but try breaking the task up and
adding trace() to see what DBI thinks is happening.

 # untested
 sub db_open {
   DBI->trace( 4, "trace.log" );
   ## XXX - add an extra ping so the second ping will work properly!
   # $dbh_cache and $dbh_cache -> ping;
   $dbh_cache = DBI -> connect( "dbi:mysql:cswwwdata;user=root" )
      unless $dbh_cache and $dbh_cache -> ping;
   DBI->trace( 0 );
   return $dbh_cache;
 }

Quote:> 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")
> }

--
Mac :})
** I normally forward private questions to the appropriate mail list. **
Ask Smarter: http://www.tuxedo.org/~esr/faqs/smart-questions.html
Give a hobbit a fish and he eats fish for a day.
Give a hobbit a ring and he eats fish for an age.

 
 
 

$dbh->ping() not pinging?

Post by Tim Bun » Tue, 07 Jan 2003 05:50:32


I don't know if this is relevant but DBD::mysql checks for a lost
connection in many places in the code and will automatically try
to reconnect 'behind the scenes' (except when AutoCommit is off).

Maybe there's some interaction/bug with that logic. Hopefully a trace
would show what's going on.

Tim.


> 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();