Forum und email

mysql_select_db

(PHP 4, PHP 5, PECL mysql:1.0)

mysql_select_db — Select a MySQL database

說明

bool mysql_select_db ( string $database_name [, resource $link_identifier ] )

Sets the current active database on the server that's associated with the specified link identifier. Every subsequent call to mysql_query() will be made on the active database.

參數

database_name

The name of the database that is to be selected.

link_identifier

MySQL 的連接識別符。如果沒有指定,預設使用最後被 mysql_connect() 打開的連接。如果沒有找到該連接,函式會嘗試呼叫 mysql_connect() 建立連接並使用它。如果發生意外,沒有找到連接或無法建立連接,系統發出 E_WARNING 級別的警告信息。

Return值

如果成功則回傳 TRUE,失敗則回傳 FALSE

範例

Example#1 mysql_select_db() example

<?php

$link 
mysql_connect('localhost''mysql_user''mysql_password');
if (!
$link) {
    die(
'Not connected : ' mysql_error());
}

// make foo the current db
$db_selected mysql_select_db('foo'$link);
if (!
$db_selected) {
    die (
'Can\'t use foo : ' mysql_error());
}
?>

註釋

Note: 為了保證向下相容性,可以使用下面的別名,但不贊成使用它: mysql_selectdb()