PHP mysqli change_user()関数
例-オブジェクト指向スタイル
指定されたデータベース接続のユーザーを変更します。
<?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_user()/ mysqli_change_user()関数は、指定されたデータベース接続のユーザーを変更し、現在のデータベースを設定します。
構文
オブジェクト指向スタイル:
$mysqli -> change_user(username, password, dbname)
手続き型:
mysqli_change_user(connection, username, password, dbname)
パラメータ値
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 |
技術的な詳細
戻り値: | 成功するとTRUE。失敗するとFALSE |
---|---|
PHPバージョン: | 5歳以上 |
例-手続き型
指定されたデータベース接続のユーザーを変更します。
<?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);
?>
❮PHPMySQLiリファレンス