PHP mysqli_select_db () function
Change the default database connection:
<?php // 假定数据库用户名:root,密码:123456,数据库:w3big $con=mysqli_connect("localhost","root","123456","w3big"); if (mysqli_connect_errno($con)) { echo "连接 MySQL 失败: " . mysqli_connect_error(); } // ...查询 "w3big" 数据库的一些 PHP 代码... // 修改数据库为 "test" mysqli_select_db($con,"test"); // ...查询 "test" 数据库的一些 PHP 代码... mysqli_close($con); ?>
Definition and Usage
mysqli_select_db () function is used to change the default database connection.
grammar
mysqli_select_db( connection,dbname ) ;
参数 | 描述 |
---|---|
connection | 必需。规定要使用的 MySQL 连接。 |
dbname | 必需,规定要使用的默认数据库。 |
technical details
return value: | If successful it returns TRUE, on failure returns FALSE. |
---|---|
PHP version: | 5+ |
PHP MySQLi Reference Manual