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

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(New page: __NOTOC__ Returns the last error string of a MySQL connection. ==Syntax== <syntaxhighlight lang="lua"> string mysql_error ( MySQLConnection handler ) </syntaxhighlight> ===Required arguments=== * '''handler:''' A ...)
 
Line 19: Line 19:
   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
else
   mysql_free_result(result)
   mysql_free_result(result) -- Free the last query result data
end
end
</syntaxhighlight>
</syntaxhighlight>

Revision as of 14:53, 13 January 2008

Returns the last error string of a MySQL connection.

Syntax

string mysql_error ( MySQLConnection handler )

Required arguments

  • handler: A valid MySQL link

Returns

The last error string. 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