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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 11:01:34 2024 UTC