true, mombu forums" /> true Php" /> #36602 : "MySQL server has gone away" with PDO::ATTR_PERSISTENT => true - Mombu the Php Forum
Mombu the Php Forum sponsored links

Go Back   Mombu the Php Forum > Php > #36602 : "MySQL server has gone away" with PDO::ATTR_PERSISTENT => true
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 11th August 06:24
georg
External User
 
Posts: 1
Default #36602 : "MySQL server has gone away" with PDO::ATTR_PERSISTENT => true


ID: 36602
Updated by: georg@php.net
Reported By: nerve at gmx dot net
Status: Open
Bug Type: PDO related
Operating System: Gentoo Linux
PHP Version: 5.1.2
New Comment:

Libmysql client library doesn't allow reconnect by default since
version 5.0.3 (Also mysql_pconnect shouldn't work after restarting
MySQL server).


Previous Comments:
------------------------------------------------------------------------

[2006-03-03 11:26:07] nerve at gmx dot net

Description:
------------
My Site connect with PDO and PDO::ATTR_PERSISTENT => true to MySQL.
If the MySQL server is restarting or a tread of the Server is killed,
the Apache tread wich is connected cant execute any statements until
Apache was restartet.
The PDO Connect return with succes, but the first query fails with
"MySQL server has gone away".
A MySQL Server restart was no problem with the old mysql_pconnect
function.

I want a detection on creation of new PDO object with persistent
connection if the connection is alive or a method to close the old
connection.

I use php 5.1.2 with apache 2.0.55 on gentoo linux with mysql
5.0.18-log

Please se my workaround code, witch make a fallback to slower non
persistent object.

Reproduce code:
---------------
// Workaround code for problem with pdo and persistent connection
try {
$db = new PDO('mysql:host='.$db_host.';dbname='.$db_db,
$db_user,$db_pw, array(PDO::ATTR_PERSISTENT => true));
$db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEP TION);
$db_info = $db->getAttribute(PDO::ATTR_SERVER_INFO); // erkennung von
toten persistenten verbindungen ...
if($db_info == "MySQL server has gone away")
{
$db = null;
$db = new PDO('mysql:host='.$db_host.';dbname='.$db_db,
$db_user,$db_pw);
}
}catch (PDOException $e)
{
print "Fehler in der DB Verbindung!: " . $e->getMessage() .
"<br/>";
$db = null;
die();
}


Expected result:
----------------
alive persistent connection if mysql is running !

Actual result:
--------------
dead mysql persistent connection if mysql was restartet !!!


------------------------------------------------------------------------


--
Edit this bug report at http://bugs.php.net/?id=36602&edit=1
  Reply With Quote


  sponsored links


Reply


Thread Tools
Display Modes




Copyright 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666