mysqli::change_user
(mysqli_change_user) Change the user who specified database connection
change_user() / mysqli_change_user() function is used to change the user for the specified database connection and set the current database.
Change the user to the specified database connection:
<?php
$mysqli = new mysqli ( "localhost" , "my_user" , "my_password" , "my_db" ) ;
if ( $mysqli -> connect_errno ) {
echo "Failed to connect to MySQL: " . $mysqli -> connect_error ;
exit ( ) ;
}
// Reset all and select a new database
$mysqli -> change_user ( "my_user" , "my_password" , "test" ) ;
$mysqli -> close ( ) ;
?>
Change the user to the specified database connection:
<?php
$con = mysqli_connect ( "localhost" , "my_user" , "my_password" , "my_db" ) ;
// Check the connection
if ( mysqli_connect_errno ( ) ) {
echo "Failed to connect to MySQL: " . mysqli_connect_error ( ) ;
exit ( ) ;
}
// Reset all and select a new database
mysqli_change_user ( $con , "my_user" , "my_password" , "test" ) ;
mysqli_close ( $con ) ;
?>
$mysqli -> change_user ( username , password , dbname )
mysqli_change_user ( connection , username , password , dbname )
| parameter | describe |
|---|---|
| connection | Required. Specifies the MySQL connection to use. |
| username | Required. Specify the MySQL username. |
| password | Required. Specify the MySQL password. |
| dbname | Required. Specifies the database to be changed to. |