PHP mysqli_change_user() Function
Definition
The mysqli_change_user() function changes the user of the specified database connection, and sets the current database.
Syntax
PHP mysqli_change_user() Function has the following syntax.
mysqli_change_user(connection,username,password,dbname);
Parameter
Parameter | Is Required | Description |
---|---|---|
connection | Required. | MySQL connection |
username | Required. | MySQL username |
password | Required. | MySQL password |
dbname | Required. | Database to change to |
Return
It returns TRUE on success or FALSE on failure.
Example
The following code changes the user of the specified database connection:
<?php/*ww w . j a v a2s .c om*/
$con=mysqli_connect("localhost","my_user","my_password","my_db");
if (mysqli_connect_errno($con)){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_change_user($link, "my_user", "my_password", "my_NewUser");
mysqli_close($con);
?>