Squirrel/Server/Functions/MySQL/mysql ping

From Liberty Unleashed Wiki
(Difference between revisions)
Jump to: navigation, search
(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

Home   |   Squirrel Scripting   |   Server Functions   |   Server Events   |   Client Functions   |   Client Events
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

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

  1.  
  2. function onScriptLoad()
  3. {
  4. LoadModule( "lu_mysql" );
  5. mySQLDatabase <- false;
  6.  
  7. try { mySQLDatabase = mysql_connect( "127.0.0.1", "user", "password", "database" ); } catch(e) { print(e); }
  8. return 1;
  9. }
  10.  
  11. function onPlayerCommand( player, command, arguments )
  12. {
  13. if( command == "ping" )
  14. {
  15. if( !mySQLDatabase ) Message( "There is no available connection." );
  16. else
  17. {
  18. if( mysql_ping( mySQLDatabase ) ) Message( "The connection was closed." );
  19. else Message( "The connection is still active." );
  20. }
  21. }
  22. }
  23.  

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.

Related Functions

User:Stormeus/Server/Functions/MySQL

Personal tools
Namespaces

Variants
Actions
Navigation
scripting
Toolbox