Bug #7120: mysql_select_db() doesn't work proprely
| From: | parienti at parienti dot org | Date: | Tue, 10 Oct 2000 15:25:23 +0000 |
| Subject: | Bug #7120: mysql_select_db() doesn't work proprely | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-34598@lists.php.net to get a copy of this message | ||
From: parienti@parienti.org
Operating system: Linux kernel 2.2.5
PHP version: 3.0.15
PHP Bug Type: MySQL related
Bug description: mysql_select_db() doesn't work proprely
The function mysql_select_db() doesn't work as expected from the
manual: "sets the current active database on the server that's
associated with the specified link identifier."
When I have two different link identifiers, with the same
connexion data (host, user, password), and when I select two
different databases for each link identifier, the first link
identifier is linked the database of the second link identifier.
I found this bug when working with several instances of the
class "DB_Sql" of the phplib, linked to different databases, with
the same "connexion data".
I reproduced the bug with the following script:
<?
$host = "localhost";
$user = "root";
$pass = "not_real_pass";
$database1 = "Brasnah";
$database2 = "BrasnahBTracking";
/* first connection to the database */
$link_id1 = mysql_pconnect( $host, $user, $pass );
/* connection to the database 1 */
if( mysql_select_db( $database1 , $link_id1 ) ) {
if( $r1 = mysql_query( "select * from Auth_User", $link_id1 ) ) {
echo "$link_id1=>$r1<br>\n";
}
}
/* second connection to the database with the same data */
$link_id2 = mysql_pconnect( $host, $user, $pass );
/* connection to the database 2 */
if( mysql_select_db( $database2 , $link_id2 ) ) {
if( $r2 = mysql_query( "select * from erttb_item ", $link_id2 ) ) {
echo "$link_id2=>$r2<br>\n";
}
}
if( $r3 = mysql_query( "select * from Auth_User", $link_id1 ) ){
echo "$link_id1=>$r3<br>\n";
} else {
echo mysql_errno( $link_id1 ).": ".mysql_error( $link_id1 )."<BR>";
}
?>
which outputs:
1=>2
3=>4
1146: Table 'BrasnahBTracking.Auth_User' doesn't exist