What is mysql_ping() function in PHP?
How does mysql_ping() works?
<?php set_time_limit(0); //Attempt to connect to the default database server $conn = mysql_connect("mysql_host", "mysql_user", "mysql_password")or die ("Could not connect"); //select database $db = mysql_select_db('my_database');// Assuming this query will take a long time $result = mysql_query($sql);if (!$result) { echo 'Query #1 failed, exiting.'; exit; } // Make sure the connection is still alive, if not, try to reconnect if (!mysql_ping($conn)) {echo 'Lost connection'; exit; } mysql_free_result($result); // So the connection is still alive, let's run another query $result2 = mysql_query($sql2);?> |