mysqli_select_db()
实例
更改连接的默认数据库:
<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// ...some PHP code for database "my_db"...
// Change database to "test"
mysqli_select_db($con,"test");
// ...some PHP code for database "test"...
mysqli_close($con);
?>
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// ...some PHP code for database "my_db"...
// Change database to "test"
mysqli_select_db($con,"test");
// ...some PHP code for database "test"...
mysqli_close($con);
?>
定义和用法
mysqli_select_db() 函数用于更改连接的默认数据库。
语法
mysqli_select_db(connection,dbname);
参数 | 描述 |
---|---|
connection | 必需。规定要使用的 MySQL 连接。 |
dbname | 必需,规定要使用的默认数据库。 |
技术细节
返回值: | 如果成功则返回 TRUE,如果失败则返回 FALSE。 |
---|---|
PHP 版本: | 5+ |