Squirrel/Server/Functions/MySQL/mysql ping
From Liberty Unleashed Wiki
(Difference between revisions)
(Created page with '{{Squirrel/Title|mysql_ping}} {{RequiresModule|lu_mysql|Modules/Squirrel/lu_mysql}} This function checks if a connection is still working, and attempts to reconnect if it is not.…') |
Revision as of 23:40, 19 November 2011
Note: This function requires the external module lu_mysql.
This function checks if a connection is still working, and attempts to reconnect if it is not.
Syntax
bool mysql_ping( UserPointer connection )
Arguments
- connection - A pointer to a MySQL connection
Return Value
mysql_ping will return FALSE if the connection is still active. Otherwise, it will return TRUE.
Example
When the scripts load, it will connect to the local MySQL server (127.0.0.1). When a player uses /ping, it will check if the connection is still active.
function onScriptLoad() { LoadModule( "lu_mysql" ); mySQLDatabase <- false; try { mySQLDatabase = mysql_connect( "127.0.0.1", "user", "password", "database" ); } catch(e) { print(e); } return 1; } function onPlayerCommand( player, command, arguments ) { if( command == "ping" ) { if( !mySQLDatabase ) Message( "There is no available connection." ); else { if( mysql_ping( mySQLDatabase ) ) Message( "The connection was closed." ); else Message( "The connection is still active." ); } } }
Notes
The functions LoadModule and mysql_close, and events onScriptLoad and onPlayerCommand were used in this example. More info about them in the corresponding pages.