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...)
 
No edit summary
Line 10: Line 10:


===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==

Revision as of 14:49, 13 January 2008

Returns the last error number of a MySQL connection.

Syntax

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
end

See also