php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #7032 Multiple mysql connections over-write eachother
Submitted: 2000-10-05 04:21 UTC Modified: 2000-10-05 21:18 UTC
From: bob at ark dot org Assigned:
Status: Closed Package: MySQL related
PHP Version: 4.0.2 OS: Unix
Private report: No CVE-ID: None
 [2000-10-05 04:21 UTC] bob at ark dot org
Assume you have 2 database in one mysql server:

Database1 (contains table: table1)
Database2 (contains table: table2)

Try this:
-----------------------
$conn_id1 = mysql_connect("localhost", "root", "");
$conn_id2 = mysql_connect("localhost", "root", "");

mysql_select_db("Database1", $conn_id1);
mysql_select_db("Database2", $conn_id2);

mysql_query("select * from table1", $conn_id1); 
mysql_query("select * from table2", $conn_id2);

-----------------
the first query will fail, b/c the 'select_db' for conn_id1 was overwritten in the 'select_db' for conn_id2: it is looking for table1 in Database2.

This hold true even inside objects, so it is difficult to create an object that accesses the database and use it in a script that accesses a different database.



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-10-05 21:18 UTC] bob at ark dot org
oops.. I am idiot.. sorry
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Mon Jun 29 05:00:02 2026 UTC