Name

mysql_ping( )

Synopsis

int mysql_ping(MYSQL *mysql)

Use this 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, 0 is returned. Otherwise, nonzero is returned.

...
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.

Get MySQL in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.