note 68526 added to function.mysql-ping

From: Date: Mon, 31 Jul 2006 19:32:47 +0000
Subject: note 68526 added to function.mysql-ping
Groups: php.notes 
Request: Send a blank email to php-notes+get-115381@lists.php.net to get a copy of this message
When using the mysql_ping command under php 5.1.2 and mysql 5.0, I was having problems with the auto-reconnect "feature", mainly that when the connection was severed, a mysql_ping would not automatically re-establish the connection to the database. The connection to the DB is dropped when the time without a query excedes the wait_timeout value in my.cnf. You can check your wait_timeout by running the query "SHOW VARIABLES;" If you're having problems auto-reconnecting when the connection is dropped, use this code: <?php $conn = mysql_connect('localhost','user','pass'); mysql_select_db('db',$conn); if (!mysql_ping ($conn)) { //here is the major trick, you have to close the connection (even though its not currently working) for it to recreate properly. mysql_close($conn); $conn = mysql_connect('localhost','user','pass'); mysql_select_db('db',$conn); } //run queries knowing that your connection is alive.... ?> ---- Server IP: 64.71.164.2 Probable Submitter: 216.16.201.50 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-ping.php Edit -- https://master.php.net/note/edit/68526 Del: integrated -- https://master.php.net/note/delete/68526/integrated Del: useless -- https://master.php.net/note/delete/68526/useless Del: bad code -- https://master.php.net/note/delete/68526/bad+code Del: spam -- https://master.php.net/note/delete/68526/spam Del: non-english -- https://master.php.net/note/delete/68526/non-english Del: in docs -- https://master.php.net/note/delete/68526/in+docs Del: other reasons-- https://master.php.net/note/delete/68526 Reject -- https://master.php.net/note/reject/68526 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#115381) next »