mysql_select_db

(PHP 4, PHP 5)

mysql_select_dbSelect a MySQL database

Warning

This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include:

Description

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

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.

Parameters

database_name

The name of the database that is to be selected.

link_identifier

The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If no connection is found or established, an E_WARNING level error is generated.

Return Values

Returns TRUE on success or FALSE on failure.

Examples

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());
}
?>

Notes

Note:

For backward compatibility, the following deprecated alias may be used: mysql_selectdb()

See Also

Коментарии

Be carefull if you are using two databases on the same server at the same time.  By default mysql_connect returns the same connection ID for multiple calls with the same server parameters, which means if you do 

<?php
  $db1 
mysql_connect(...stuff...);
 
$db2 mysql_connect(...stuff...);
 
mysql_select_db('db1'$db1);
 
mysql_select_db('db2'$db2); 
?>

then $db1 will actually have selected the database 'db2', because the second call to mysql_connect just returned the already opened connection ID !

You have two options here, eiher you have to call mysql_select_db before each query you do, or if you're using php4.2+ there is a parameter to mysql_connect to force the creation of a new link.
2004-01-16 18:45:07
http://php5.kiev.ua/manual/ru/function.mysql-select-db.html
Автор:
About opening connections if the same parameters to mysql_connect() are used: this can be avoided by using the 'new_link' parameter to that function.

This parameter has been available since PHP 4.2.0 and allows you to open a new link even if the call uses the same parameters.
2005-08-19 08:09:38
http://php5.kiev.ua/manual/ru/function.mysql-select-db.html

    Поддержать сайт на родительском проекте КГБ