- 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
廣告