Modules/MTA-MySQL/mysql change user
		
		
		
		Jump to navigation
		Jump to search
		
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 ( resource )
  if (resouce == 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