Modules/MTA-MySQL/mysql change user: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
<pageclass class="#AA7592" subcaption="MTA-MySQL Module"></pageclass> | |||
__NOTOC__ | __NOTOC__ | ||
{{ModuleFunction|MTA-MySQL}} | {{ModuleFunction|MTA-MySQL}} | ||
Line 21: | Line 22: | ||
'''Example 1:''' | '''Example 1:''' | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function resourceStart ( | function resourceStart ( res ) | ||
if ( | if (res == getThisResource()) then | ||
myhandler = mysql_connect("localhost", "writer_user", "password", "mta_users") -- Start with a read-write username | myhandler = mysql_connect("localhost", "writer_user", "password", "mta_users") -- Start with a read-write username | ||
if (not myhandler) then | if (not myhandler) then |
Latest revision as of 16:43, 11 February 2015
This function is provided by the external module MTA-MySQL. You must install this module to use this function. | |
Changes the current MySQL session authentication.
Syntax
bool mysql_change_user ( MySQLConnection handler, string new_username, string new_password [, string new_database ] )
Required arguments
- handler: A valid MySQL link
- new_username: The new username
- new_password: The new username password
Optional arguments
NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.
- new_database: Start the new session using a new default database
Returns
It it succeeds returns true, in other case returns false
Example
Example 1:
function resourceStart ( res ) if (res == getThisResource()) then myhandler = mysql_connect("localhost", "writer_user", "password", "mta_users") -- Start with a read-write username if (not myhandler) then outputDebugString("Unable to connect to the database: (" .. mysql_errno(handler) .. ") " .. mysql_error(handler)) else -- Apply some changes to the database here if (not mysql_change_user(myhandler, "localhost", "reader_user", "password", "mta_users")) then -- Change to a read-only user outputDebugString("Unable to set the database read-only user: (" .. mysql_errno(handler) .. ") " .. mysql_error(handler)) mysql_close(myhandler) -- Close the MySQL connection end end end end addEventHandler("onResourceStart", getRootElement(), resourceStart)
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