Modules/MTA-MySQL/mysql query: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
mNo edit summary |
||
(2 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
<pageclass class="#AA7592" subcaption="MTA-MySQL Module"></pageclass> | |||
__NOTOC__ | __NOTOC__ | ||
{{ModuleFunction|MTA-MySQL}} | |||
Executes a query in the server and retreives the result. | Executes a query in the server and retreives the result. | ||
''' | '''IMPORTANT:''' It is '''strongly''' recommended to call [[Modules/MTA-MySQL/mysql_free_result|mysql_free_result]] after a query, | ||
specially if it returns some data. Query results can be automatically deleted | specially if it returns some data. Query results can be automatically deleted | ||
by the lua garbage collector, so if you '''forget''' to free a result it will be | by the lua garbage collector, so if you '''forget''' to free a result it will be |
Latest revision as of 17:45, 5 January 2011
This function is provided by the external module MTA-MySQL. You must install this module to use this function. | |
Executes a query in the server and retreives the result.
IMPORTANT: It is strongly recommended to call mysql_free_result after a query, specially if it returns some data. Query results can be automatically deleted by the lua garbage collector, so if you forget to free a result it will be freed at some time in the future, but it doesn't know the real result data size in memory so it can delay the memory destroying more than it should.
Syntax
MySQLResult mysql_query ( MySQLConnection handler, string query )
Required arguments
- handler: A valid MySQL link
- query: The executing query
Returns
In case of error this function returns nil. IF not, a MySQLResult handler. Check the MySQL result managing functions to see how to retreive the data from it.
Example
Example 1:
local result = mysql_query(handler, "SELECT * FROM some_table") if (not result) then outputDebugString("Error executing the query: (" .. mysql_errno(handler) .. ") " .. mysql_error(handler)) else mysql_free_result(result) -- Freeing the result is IMPORTANT end
See also
Result managing functions
- mysql_data_seek
- mysql_fetch_field
- mysql_fields
- mysql_fetch_lengths
- mysql_fetch_row
- mysql_rows
- mysql_fetch_assoc
- mysql_rows_assoc
- mysql_field_length
- mysql_field_name
- mysql_field_seek
- mysql_field_tell
- mysql_num_fields
- mysql_num_rows
- mysql_result
- mysql_free_result
- mysql_null
MySQL handler functions
- mysql_connect
- mysql_close
- mysql_errno
- mysql_error
- mysql_ping
- mysql_select_db
- mysql_escape_string
- mysql_affected_rows
- mysql_change_user
- mysql_get_character_set_info
- mysql_get_client_info
- mysql_get_client_version
- mysql_get_host_info
- mysql_get_proto_info
- mysql_get_server_info
- mysql_get_server_version
- mysql_hex_string
- mysql_info
- mysql_insert_id
- mysql_query
- mysql_unbuffered_query
- mysql_set_character_set
- mysql_stat
- mysql_warning_count