April 2008
Intermediate to advanced
566 pages
21h 55m
English
mysql_ping()
int mysql_ping(MYSQL *mysql)
Use this function to determine whether the current
MYSQL connection is still open. If it’s not open,
the function attempts to reestablish the connection. If the connection
is open or is reestablished, zero is returned. Otherwise, a nonzero
value is returned. Here is an example:
...
MYSQL *mysql;
int main( )
{
...
test_connection( );
mysql_close(mysql);
test_connection( );
}
test_connection( )
{
int live;
live = mysql_ping(mysql);
if(live){ printf("Connection not alive. \n"); }
else { printf("Connection alive. \n"); }
}This excerpt employs a user function to test for a MySQL connection.
Read now
Unlock full access