PHP Tutorial - 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

ParameterIs RequiredDescription
connectionRequired.MySQL connection
usernameRequired.MySQL username
passwordRequired.MySQL password
dbnameRequired.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/*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);
?>