mysql_change_user() - 0
Changes the user and causes the database specified by
db to become the default (current) database
on the connection specified by mysql. In
subsequent queries, this database is the default for table
references that include no explicit database specifier.dbmysqlmysql_change_user() fails if the
connected user cannot be authenticated or does not have
permission to use the database. In this case, the user and
database are not changed.mysql_change_user()mysql_change_user()Pass a db parameter of
NULL if you do not want to have a default
database.dbNULLThis function resets the session state as if one had done a new
connect and reauthenticated. (See
Section 25.8.16, “Controlling Automatic Reconnection Behavior”.) It always performs a
ROLLBACK of
any active transactions, closes and drops all temporary tables,
and unlocks all locked tables. Session system variables are
reset to the values of the corresponding global system
variables. Prepared statements are released and
HANDLER variables are closed.
Locks acquired with GET_LOCK()
are released. These effects occur even if the user did not
change.Section 25.8.16, “Controlling Automatic Reconnection Behavior”ROLLBACKROLLBACKHANDLERHANDLERGET_LOCK()GET_LOCK()To reset the connection state in a more lightweight manner
without changing the user, use
mysql_reset_connection().mysql_reset_connection()mysql_reset_connection()
Syntax
my_bool mysql_change_user(MYSQL *mysql, const char
*user, const char *password, const char *db)
Example
if (mysql_change_user(&mysql, "user", "password", "new_database"))
{
fprintf(stderr, "Failed to change user. Error: %s\n",
mysql_error(&mysql));
}
Output / Return Value
Zero for success. Nonzero if an error occurred.
Limitations
Alternatives / See Also
Reference