Modules/MTA-MySQL/mysql ping: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
mNo edit summary
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
<pageclass class="#AA7592" subcaption="MTA-MySQL Module"></pageclass>
__NOTOC__
__NOTOC__
{{ModuleFunction|MTA-MySQL}}
{{ModuleFunction|MTA-MySQL}}
Line 31: Line 32:
==See also==
==See also==
{{Modules/MTA-MySQL/Handler_functions}}
{{Modules/MTA-MySQL/Handler_functions}}
[[RU:Modules/MTA-MySQL/mysql_ping]]

Latest revision as of 16:21, 2 December 2017


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