HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
PHP MySQLi Reference : Change the user of the specified database connection
The change_user() / mysqli_change_user() function changes the user of the specified database connection, and sets the current database.
Object oriented style:
Procedural style:
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 |
Return Value: | TRUE on success. FALSE on failure |
---|---|
PHP Version: | 5+ |
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