php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #7120 mysql_select_db() doesn't work proprely
Submitted: 2000-10-10 11:25 UTC Modified: 2000-10-12 07:40 UTC
From: parienti at parienti dot org Assigned:
Status: Closed Package: MySQL related
PHP Version: 3.0.15 OS: Linux kernel 2.2.5
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: parienti at parienti dot org
New email:
PHP Version: OS:

 

 [2000-10-10 11:25 UTC] parienti at parienti dot 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-10-12 07:40 UTC] sniper@php.net
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
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 13 03:01:32 2025 UTC