Modules/MTA-MySQL/mysql insert id: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
mNo edit summary |
||
Line 1: | Line 1: | ||
<pageclass class="#AA7592" subcaption="MTA-MySQL Module"></pageclass> | |||
__NOTOC__ | __NOTOC__ | ||
{{ModuleFunction|MTA-MySQL}} | {{ModuleFunction|MTA-MySQL}} |
Latest revision as of 17:44, 5 January 2011
This function is provided by the external module MTA-MySQL. You must install this module to use this function. | |
Returns the value generated for an AUTO_INCREMENT field in the last query.
For more information about when is this value updated visit http://dev.mysql.com/doc/refman/5.0/en/mysql-insert-id.html
Syntax
int mysql_insert_id ( MySQLConnection handler )
Required arguments
- handler: A valid MySQL link
Returns
The value generated for an AUTO_INCREMENT field in the last query.
Example
Example 1: This example creates an account for a player when they use /register, and tells them their database id.
function RegisterPlayer(playerSource, commandName, _password) local name = mysql_escape_string(handler, getPlayerName(playerSource)) -- Escape the strings to avoid SQL-Injection local password = mysql_escape_string(handler, _password) local query = "INSERT INTO account SET name='" .. name .. "', password=MD5('" .. password .. "')" if (mysql_query(handler, query)) then outputChatBox("Account created successfuly with id #" .. mysql_insert_id(handler), playerSource) else outputChatBox("An error has occured when trying to create your account.", playerSource) end end addCommandHandler("register", RegisterPlayer)
See also
- 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