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

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(New page: __NOTOC__ Returns the last error number of a MySQL connection. ==Syntax== <syntaxhighlight lang="lua"> mysql_errno ( MySQLConnection handler ) </syntaxhighlight> ===Required arguments=== * '''handler:''' A valid M...)
 
mNo edit summary
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<pageclass class="#AA7592" subcaption="MTA-MySQL Module"></pageclass>
__NOTOC__
__NOTOC__
{{ModuleFunction|MTA-MySQL}}
Returns the last error number of a MySQL connection.
Returns the last error number of a MySQL connection.


==Syntax==
==Syntax==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
mysql_errno ( MySQLConnection handler )
int mysql_errno ( MySQLConnection handler )
</syntaxhighlight>
</syntaxhighlight>
===Required arguments===
===Required arguments===
Line 10: Line 12:


===Returns===
===Returns===
The last error number, zero if something failed. Visit http://dev.mysql.com/doc/refman/5.0/en/error-handling.html for a list of error codes.
The last error number, zero if nothing failed. Visit http://dev.mysql.com/doc/refman/5.0/en/error-handling.html for a list of error codes.


==Example==
==Example==
Line 18: Line 20:
if (not result) then -- The query failed
if (not result) then -- The query failed
   outputDebugString("mysql_query failed: (" .. mysql_errno(handler) .. ") " .. mysql_error(handler)) -- Show the reason
   outputDebugString("mysql_query failed: (" .. mysql_errno(handler) .. ") " .. mysql_error(handler)) -- Show the reason
else
  mysql_free_result(result) -- Free the last query result data
end
end
</syntaxhighlight>
</syntaxhighlight>
Line 23: Line 27:
==See also==
==See also==
{{Modules/MTA-MySQL/Handler_functions}}
{{Modules/MTA-MySQL/Handler_functions}}
[[RU:Modules/MTA-MySQL/mysql_errno]]

Latest revision as of 15:30, 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.

Returns the last error number of a MySQL connection.

Syntax

int mysql_errno ( MySQLConnection handler )

Required arguments

  • handler: A valid MySQL link

Returns

The last error number, zero if nothing failed. Visit http://dev.mysql.com/doc/refman/5.0/en/error-handling.html for a list of error codes.

Example

Example 1: This example sends a query to the server and if it fails, shows the reason.

result = mysql_query(handler, "SELECT FROM table") -- We have a syntax error in the query
if (not result) then -- The query failed
  outputDebugString("mysql_query failed: (" .. mysql_errno(handler) .. ") " .. mysql_error(handler)) -- Show the reason
else
  mysql_free_result(result) -- Free the last query result data
end

See also