Modules/MTA-MySQL/mysql ping

From Multi Theft Auto: Wiki
Revision as of 15:00, 13 January 2008 by Ryden (talk | contribs) (New page: __NOTOC__ Checks if the given MySQL connection is still alive. ==Syntax== <syntaxhighlight lang="lua"> bool mysql_ping ( MySQLConnection handler ) </syntaxhighlight> ===Required arguments=== * '''handler:''' A val...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Checks if the given MySQL connection is still alive.

Syntax

bool mysql_ping ( MySQLConnection handler )

Required arguments

  • handler: A valid MySQL link

Returns

true is the connection is still alive, false if not.

Example

Example 1: This example checks if the MySQL connection is still alive when a player connects, to be able to fetch their data.

myhandler = mysql_connect("localhost", "user", "password", "mta_users")

function checkMySQLConnection ( )
  if (mysql_ping(myhandler) == false) then -- We lost the connection to the MySQL server
    outputDebugString("Lost connection to the MySQL server, reconnecting ...")
    mysql_close(myhandler)
    myhandler = mysql_connect("localhost", "user", "password", "mta_users") -- Reconnect to the MySQL server
  end
end

addEventHandler("onPlayerJoin", getRootElement(), checkMySQLConnection)

See also