PHP 4.0 Bug #7120 Updated: mysql_select_db() doesn't work proprely
| From: | Bug Database | Date: | Thu, 12 Oct 2000 11:40:03 +0000 |
| Subject: | PHP 4.0 Bug #7120 Updated: mysql_select_db() doesn't work proprely | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-34765@lists.php.net to get a copy of this message | ||
ID: 7120
Updated by: sniper
Reported By: parienti@parienti.org
Status: Closed
Bug Type: MySQL related
Assigned To:
Comments:
Please read again:
http://www.php.net/manual/function.mysql-pconnect.php
Use mysql_select_db() everytime you need to change
database to another.
i.e. before $r3.. line add a mysql_select_db() clause.
--Jani
Previous Comments:
---------------------------------------------------------------------------
[2000-10-10 11:25:23] parienti@parienti.org
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
---------------------------------------------------------------------------
Full Bug description available at: http://bugs.php.net/?id=7120