List Info

Thread: note 68526 added to function.mysql-ping




note 68526 added to function.mysql-ping
user name
2006-07-31 19:32:47
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  -- h
ttps://master.php.net/note/delete/68526/integrated
Del: useless     -- http
s://master.php.net/note/delete/68526/useless
Del: bad code    -- htt
ps://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     -- http
s://master.php.net/note/delete/68526/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/68526
Reject      -- https://mast
er.php.net/note/reject/68526
Search      -- https://
master.php.net/manage/user-notes.php

-- 
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )