ID:               36602
 User updated by:  nerve at gmx dot 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:

That's right, after installing the new mysql i havent testet it. 
But what to do ? I can't explicitli close the persistent connections
until apache is restartet. 
Same problem happen if mysql timeout is reached.

Can we make a solution for the php user how don't want to programm a
workaround to normal connections ? (Transparent solution in php source
code ? )

Thank's for your help.


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

[2006-03-03 15:32:53] [EMAIL PROTECTED]

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

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

[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_EXCEPTION);
$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 via email to