Name

mysql_change_user( )

Synopsis

mysql_change_user(user, password[, database, connection])

Use this to change the username for a MySQL connection. The new username is given as the first argument and the password for that user as the second. A different database from the one in use may be given as a third argument. The user information may be changed for a different MySQL connection by specifying it as the fourth argument. If the function is successful, true is returned; false is returned if it’s unsuccessful. This function is no longer available as of Version 4 of PHP. Instead, a new connection should be established with a different user by using the mysql_connect( ) function:

...
mysql_connect('localhost', 'hui', 'shorty');
...
mysql_change_user('russell','dyer');
...

In this example, we needed to change the user in the script from hui to russell. If there had been a third argument, we would have changed to another database.

Get MySQL in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.