Detect database disconnect in mysql_fetch_row on mysql_unbuffered_query in PHP

149 Views Asked by At

I have a code that connects to a database. It executes a select statement over a large table using mysql_unbuffered_query. It goes over the records using mysql_fetch_row and finally frees the result. Sometimes, the server where the code is running, disconnects from the network and cannot reach the database. How do I detect this disconnect while reading records with mysql_fetch_row? Here is example code:

$mysql_link  = mysql_connect( 'server', 'uname', 'pword' );

if ( mysql_select_db( 'large_database', $mysql_link ) ) 
{ 
    $query = "SELECT * FROM my_large_table"; 
    $records = mysql_unbuffered_query( $query, $mysql_link ); 
    while ( $record = mysql_fetch_row( $records ) ) // database disconnects here 
    { 
        // do something with the record 
    } 
}
0

There are 0 best solutions below