Modules/MTA-MySQL/mysql ping

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.


Package-x-generic.png This function is provided by the external module MTA-MySQL. You must install this module to use this function.

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