- MySQLi 教程
- MySQLi - 主页
- MySQLi - 简介
- MySQLi - PHP 语法
- MySQLi - 连接
- MySQLi - 创建数据库
- MySQLi - 删除数据库
- MySQLi - 选择数据库
- MySQLi - 创建表
- MySQLi - 删除表
- MySQLi - 插入查询
- MySQLi - 选择查询
- MySQLi - Where 子句
- MySQLi - 更新查询
- MySQLi - 删除查询
- MySQLi - Like 子句
- MySQLi - 排序结果
- MySQLi - 使用连接
- MySQLi - 处理 NULL 值
- 获取和使用 MySQLi 元数据
- MySQL
- MySQL - 安装
- MySQL - 管理
- MySQL - 数据类型
- MySQL - 正则表达式
- MySQL - 事务
- MySQL - Alter 命令
- MySQL - 索引
- MySQL - 临时表
- MySQL - 克隆表
- MySQL - 使用序列
- MySQL - 处理重复内容
- MySQLi 实用资源
- MySQLi - 常用函数
- MySQLi - 快速指南
- MySQLi - 实用资源
- MySQLi - 讨论
MySQLi - 选择数据库
语法
bool mysqli_select_db ( mysqli $link , string $dbname )
定义和用法
用于选择用于数据库查询的默认数据库。
示例
试用以下示例 −
<?php
$servername = "localhost:3306";
$username = "root";
$password = "";
$dbname = "TUTORIALS";
$tmp = NULL;
$conn = new mysqli($servername, $username, $password, $dbname);
if (!$conn->real_connect($servername, $username, $password, $dbname)) {
die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error());
}
echo 'Success... ' . mysqli_get_host_info($conn) . "\n";
if ($result = $conn->query("SELECT DATABASE()")) {
$row = $result->fetch_row();
printf("Default database is %s.\n", $row[0]);
$result->close();
}
$conn->select_db("test");
if ($result = $conn->query("SELECT DATABASE()")) {
$row = $result->fetch_row();
printf("Default database is %s.\n", $row[0]);
$result->close();
}
$conn->close();
?>
上述代码的示例输出应如下所示 −
Success... localhost:3306 via TCP/IP Default database is tutorials. Default database is test.
mysqli_useful_functions.htm
广告