PHP mysqli change_user() Function

❮ PHP MySQLi Reference

Example - Object Oriented style

Change the user of 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();
?>

Look at example of procedural style at the bottom.


Definition and Usage

The change_user() / mysqli_change_user() function changes the user of the specified database connection, and sets the current database.


Syntax

Object oriented style:

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

Procedural style:

mysqli_change_user(connection, username, password, dbname)

Parameter Values

Parameter Description
connection Required. Specifies the MySQL connection to use
username Required. Specifies the MySQL user name
password Required. Specifies the MySQL password
dbname Required. Specifies the database to change to

Technical Details

Return Value: TRUE on success. FALSE on failure
PHP Version: 5+

Example - Procedural style

Change the user of the specified database connection:

<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");

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


❮ PHP MySQLi Reference
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.