php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14906 The function mysql_select_db set the db for other link ids than specified.
Submitted: 2002-01-07 07:27 UTC Modified: 2002-03-11 08:34 UTC
Votes:5
Avg. Score:5.0 ± 0.0
Reproduced:4 of 4 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: jparneodo at yahoo dot fr Assigned:
Status: Closed Package: MySQL related
PHP Version: 4.1.0 OS: RedHat 7.1
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: jparneodo at yahoo dot fr
New email:
PHP Version: OS:

 

 [2002-01-07 07:27 UTC] jparneodo at yahoo dot fr
PHP 4.1.0 and MySQL 3.23.41-log

The function mysql_select_db set the db for other link
identifiers than specified.

Doc:
bool mysql_select_db (string database_name, resource [link_identifier])
mysql_select_db() sets the current active database on the server that's associated with the specified link identifier. If no link identifier is specified, the last opened link is assumed. If no link is open, the function will try to establish a link as if mysql_connect() was called without arguments, and use it. 

The table my_table is in db1 but the active database
seems to be test on link #8.

Here the result:
mysql_pconnect() id1=Resource id #8
mysql_select_db(db1,Resource id #8)
mysql_pconnect() id2=Resource id #9
mysql_select_db(test,Resource id #9)
mysql_query(select * from my_table,Resource id #8)
failed: Table 'test.my_table' doesn't exist

Here the source:
$id1=mysql_pconnect($host,$user,$pass);
if($id1==false){
	die("<br>mysql_pconnect() failed: ".mysql_error());
}
echo "<br>mysql_pconnect() id1=$id1";

$b=mysql_select_db($db1,$id1);
if($b==false){
	die("<br>mysql_select_db($db1,$id1)
failed:".mysql_error());
}
echo "<br>mysql_select_db($db1,$id1)";

$id2=mysql_pconnect($host,$user,$pass);
if($id2==false){
	echo "<br>mysql_pconnect() failed: ".mysql_error();
}
echo "<br>mysql_pconnect() id2=$id2";

$b=mysql_select_db($db2,$id2);
if($b==false){
	die("<br>mysql_select_db($db2,$id2)
failed:".mysql_error());
}
echo "<br>mysql_select_db($db2,$id2)";

$sql='select * from my_table';
$result=mysql_query($sql,$id1);
if($result==false){
	die("<br>mysql_query($sql,$id1)
failed:".mysql_error());
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-03-11 07:24 UTC] newspost at jerviss dot org
On my Slackware 3.6 box (not that it matters, since everything has been built from source [php 4.0.6, 4.1.1 and 4.1.2, mysql 3.22.30]), I get essentially the same results.  I don't remember if the resource IDs were the same, but I rewrote a few of my database libraries because of this.

Basically, I had to write my database wrappers to never select a database and always user mysql_db_query() because if someone using the library connected with the same host/user/pass and selected a database, the most current one would be used by both/all connections.

Please don't take mysql_db_query() away until this is sorted out.  (and maybe not even then)  :)
 [2002-03-11 08:34 UTC] mfischer@php.net
This is a known limitation and a workaround exists in current CVS and upcomming 4.2.0 version which has a new, additional/optional parameter to mysql_connect() [NOT! pconnect!] which forces the creation of a truly new link and not re-use an existing one.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 16 04:01:28 2024 UTC