PHP mysql_ping() Function

Definition and Usage

The mysql_ping() function pings a server connection and reconnects if there is no connection.

Returns true if a connection exists. Returns false if it fails.

Syntax

mysql_ping(connection)
Parameter Description
connection Optional. Specifies the MySQL connection. If not specified, the last connection is used.

Tips and Comments

Note:This function can be used to check if the server has closed the connection for a long time.

Example

<?php
$con = mysql_connect("localhost", "hello", "321");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db("test_db", $con);
$sql = "SELECT * from Person";
$result = mysql_query($sql,$link);
mysql_ping();
// Some code...
mysql_close($con);
?>