The mysqli_change_user() function changes the user of the specified database connection, and sets the current database.
PHP mysqli_change_user() Function has the following syntax.
mysqli_change_user(connection,username,password,dbname);
Parameter | Is Required | Description |
---|---|---|
connection | Required. | MySQL connection |
username | Required. | MySQL username |
password | Required. | MySQL password |
dbname | Required. | Database to change to |
It returns TRUE on success or FALSE on failure.
The following code changes the user of the specified database connection:
<?php/*from w w w. j av a2 s . co m*/
$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);
?>