Re: PHP 4.0 Bug #7032: Multiple mysql connections over-write eachother

From: Date: Wed, 04 Oct 2000 20:35:47 +0000
Subject: Re: PHP 4.0 Bug #7032: Multiple mysql connections over-write eachother
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-34260@lists.php.net to get a copy of this message
This is clearly documented within the mysql_connect() documentation. If a second call is made to mysql_connect() with the same arguments, no new link will be established, but instead, the link identifier of the already opened link will be returned. Try using mysql_db_query() instead -- ------------------------- $conn_id = mysql_connect("localhost","root",""); mysql_db_query("Database1", "select * from table1", $conn_id); mysql_db_query("Database2", "select * from table2", $conn_id); ------------------------- Chris On 5 Oct 2000 bob@ark.org wrote: > From: bob@ark.org > Operating system: Unix > PHP version: 4.0.2 > PHP Bug Type: MySQL related > Bug description: Multiple mysql connections over-write eachother > > 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. > > > > > > -- > PHP Development Mailing List <http://www.php.net/> > To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net > For additional commands, e-mail: php-dev-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > >

« previous php.dev (#34260) next »