Modules/MTA-MySQL/mysql change user: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(New page: __NOTOC__ Changes the current MySQL session authentication. ==Syntax== <syntaxhighlight lang="lua"> bool mysql_change_user ( MySQLConnection handler, string new_username, string new_password [, string n...)
 
No edit summary
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{ModuleFunction|MTA-MySQL}}
Changes the current MySQL session authentication.
Changes the current MySQL session authentication.



Revision as of 17:59, 14 January 2008


Package-x-generic.png 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 ( 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