Current Location: Home> Function Categories> mysqli::change_user

mysqli::change_user

(mysqli_change_user) Change the user who specified database connection
Name:mysqli::change_user
Category:MySQLi
Programming Language:php
One-line Description:Changes the user to which the specified database connection is.

Definition and usage

change_user() / mysqli_change_user() function is used to change the user for the specified database connection and set the current database.

Example

Example 1 - Object-Oriented Style

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 ( ) ;
?>

Example 2 - Procedural Style

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 ) ;
?>

grammar

Object-oriented style:

 $mysqli -> change_user ( username , password , dbname )

Procedural Style:

 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.
Similar Functions
Popular Articles