PHP mysqli change_user() Fungsi
Contoh - Gaya Berorientasi Objek
Ubah pengguna koneksi database yang ditentukan:
<?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();
?>
Lihatlah contoh gaya prosedural di bagian bawah.
Definisi dan Penggunaan
Fungsi change_user() / mysqli_change_user() mengubah pengguna dari koneksi database yang ditentukan, dan menetapkan database saat ini.
Sintaksis
Gaya berorientasi objek:
$mysqli -> change_user(username, password, dbname)
Gaya prosedural:
mysqli_change_user(connection, username, password, dbname)
Nilai Parameter
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 |
Detail Teknis
Nilai Kembali: | BENAR pada kesuksesan. SALAH pada kegagalan |
---|---|
Versi PHP: | 5+ |
Contoh - Gaya prosedural
Ubah pengguna koneksi database yang ditentukan:
<?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);
?>
Referensi PHP MySQLi