mysql_ping

(PHP 4 >= 4.3.0, PHP 5)

mysql_ping -- Ping 一个服务器连接,如果没有连接则重新连接

说明

bool mysql_ping ( [resource link_identifier] )

mysql_ping() 检查到服务器的连接是否正常。如果断开,则自动尝试连接。本函数可用于空闲很久的脚本来检查服务器是否关闭了连接,如果有必要则重新连接上。如果到服务器的连接可用则 mysql_ping() 返回 TRUE,否则返回 FALSE

参见 mysql_thread_id()mysql_list_processes()


add a note add a note User Contributed Notes
cybot2000 at yahoo dot de
26-May-2005 07:44
It should be noted that mysql_ping() seems to reset the error message on the server.
I used it to check whether the connection was still alive before reading the error message via mysql_error() and it always returned an empty string. Upon removing the connection check everything worked.
vinicius at teracom dot com dot br
16-Mar-2004 11:35
Is important to remember that if your first connection to mysql don't works, mysql_ping will always return true! So, if you want to check if mysql is connected, first of all you must check if mysql_connect do not returns false and then you can begin to check mysql_ping.