MDB2 Bug #15232
type: channel
description: [Bogus] Multiple database handles seem to collide
language: en-us
generator agent: bugs
update period: hourly
update frequency: 1
update base: 2000-01-01T12:00+00:00
items: danielc [2012-10-24 19:05]
items: ghada [2011-09-05 00:16]
items: phreek_11 [2010-07-14 07:54]
items: alec [2010-06-10 14:40]
items: doconnor [2010-03-02 15:42]
items: c0ntax [2008-12-05 13:18]
items: quipo [2008-12-04 09:28]
type: Bug
summary: Multiple database handles seem to collide
description: Description: ------------ If I create two database handles and then query against the first one I created, it runs the query against the second database connection. It seems that the most recent one is stamping over the top of the last. Test script: --------------- From the command line: mysqladmin -u bob -p buttons create test1 mysqladmin -u bob -p buttons create test2 mysql -u bob -p buttons -e 'create table a (a int primary key); insert into a (a) values (1);' test1 mysql -u bob -p buttons -e 'create table b (b int primary key); insert into b (b) values (1);' test2 Now the script: <?php require('MDB2.php'); $dsn1 = 'mysql://bob:buttons@localhost/test1'; $dsn2 = 'mysql://bob:buttons@localhost/test2'; $options = array( 'debug' => (true), 'portability' => MDB2_PORTABILITY_ALL, 'persistent' => false, 'debug_handler' => 'db_debug_handler' ); $dbh1 =& MDB2::connect($dsn1, $options); if (PEAR::isError($dbh1)) { print 'DBH1: ' . $dbh1->getMessage() . " \n"; } $dbh2 =& MDB2::connect($dsn2, $options); if (PEAR::isError($dbh2)) { print 'DBH2: ' . $dbh2->getMessage() . " \n"; } $result1 =& $dbh1->query('SELECT * FROM a LIMIT 1'); var_dump($result1); //$result2 =& $dbh2->query('SELECT * FROM b LIMIT 1'); //var_dump($result2); //$result3 =& $dbh1->query('SELECT * FROM a LIMIT 1'); //var_dump($result3); function db_debug_handler(&$db, $scope, $message, $is_manip = null) { // call the default handler just so that we can later call getDebugOutput return MDB2_defaultDebugOutput($db, $scope, $message, $is_manip); } ?> Expected result: ---------------- A MDB2_BufferedResult_mysql object with the contents of table 'a' in it Actual result: -------------- An MDB2_Error object with the following message: _doQuery: [Error message: Could not execute statement] [Last executed query: SELECT * FROM a LIMIT 1] [Native code: 1146] [Native message: Table 'test2.a' doesn't exist] The full backtrace is below. Notice how throughout all of it, the connected_database_name is test1 (as it should be) …
reporter: c0ntax
state: WorksForMe
type: item
title: c0ntax
description: MDB2 Bug Reported by c0ntax 2008-12-04T09:17:44+00:00 PHP: 5.2.0 OS: 5.0.32-Debian_7etch8-log Package Version: 2.4.1 Description: ------------ If I create two database handles and then query against the first one I created, it runs the query against the second database connection. It seems that the most recent one is stamping over the top of the last. Test script: --------------- From the command line: mysqladmin -u bob -p buttons create test1 mysqladmin -u bob -p buttons create test2 mysql -u bob -p buttons -e 'create table a (a int primary key); insert into a (a) values (1);' test1 mysql -u bob -p buttons -e 'create table b (b int primary key); insert into b (b) values (1);' test2 Now the script: <?php require('MDB2.php'); $dsn1 = 'mysql://bob:buttons@localhost/test1'; $dsn2 = 'mysql://bob:buttons@localhost/test2'; $options = array( 'debug' => (true), 'portability' => MDB2_PORTABILITY_ALL, 'persistent' => false, 'debug_handler' => 'db_debug_handler' ); $dbh1 =& MDB2::connect($dsn1, $options); if (PEAR::isError($dbh1)) { print 'DBH1: ' . $dbh1->getMessage() . " \n"; } $dbh2 =& MDB2::connect($dsn2, $options); if (PEAR::isError($dbh2)) { print 'DBH2: ' . $dbh2->getMessage() . " \n"; } $result1 =& $dbh1->query('SELECT * FROM a LIMIT 1'); var_dump($result1); //$result2 =& $dbh2->query('SELECT * FROM b LIMIT 1'); //var_dump($result2); //$result3 =& $dbh1->query('SELECT * FROM a LIMIT 1'); //var_dump($result3); function db_debug_handler(&$db, $scope, $message, $is_manip = null) { // call the default handler just so that we can later call getDebugOutput return MDB2_defaultDebugOutput($db, $scope, $message, $is_manip); } ?> Expected result: ---------------- A MDB2_BufferedResult_mysql object with the contents of table 'a' in it Actual result: -------------- An MDB2_Error object with the following message: _doQuery: [Error message: Could not execute statement] [Last executed query: SELECT * FROM a LIMIT 1] [Native code: 1146] [Native message: Table 'test2.a' doesn't exist] …
encoded: MDB2 Bug Reported by c0ntax 2008-12-04T09:17:44+00:00 PHP: 5.2.0 OS: 5.0.32-Debian_7etch8-log Package Version: 2.4.1 Description: ------------ If I create two database handles and then query against the first one I created, it runs the query against the second database connection. It seems that the most recent one is stamping over the top of the last. Test script: --------------- From the command line: mysqladmin -u bob -p buttons create test1 mysqladmin -u bob -p buttons create test2 mysql -u bob -p buttons -e 'create table a (a int primary key); insert into a (a) values (1);' test1 mysql -u bob -p buttons -e 'create table b (b int primary key); insert into b (b) values (1);' test2 Now the script: <?php require('MDB2.php'); $dsn1 = 'mysql://bob:buttons@localhost/test1'; $dsn2 = 'mysql://bob:buttons@localhost/test2'; $options = array( 'debug' => (true), 'portability' => MDB2_PORTABILITY_ALL, 'persistent' => false, 'debug_handler' => 'db_debug_handler' ); $dbh1 =& MDB2::connect($dsn1, $options); if (PEAR::isError($dbh1)) { print 'DBH1: ' . $dbh1->getMessage() . " \n"; } $dbh2 =& MDB2::connect($dsn2, $options); if (PEAR::isError($dbh2)) { print 'DBH2: ' . $dbh2->getMessage() . " \n"; } $result1 =& $dbh1->query('SELECT * FROM a LIMIT 1'); var_dump($result1); //$result2 =& $dbh2->query('SELECT * FROM b LIMIT 1'); //var_dump($result2); //$result3 =& $dbh1->query('SELECT * FROM a LIMIT 1'); //var_dump($result3); function db_debug_handler(&$db, $scope, $message, $is_manip = null) { // call the default handler just so that we can later call getDebugOutput return MDB2_defaultDebugOutput($db, $scope, $message, $is_manip); } ?> Expected result: ---------------- A MDB2_BufferedResult_mysql object with the contents of table 'a' in it Actual result: -------------- An MDB2_Error object with the following message: _doQuery: [Error message: Could not execute statement] [Last executed query: SELECT * FROM a LIMIT 1] [Native code: 1146] [Native message: Table 'test2.a' doesn't exist] …
date: 2008-12-04T09:17:44+00:00

c0ntax
type: User
account name: c0ntax

danielc [2012-10-24 19:05]
type: item
description: -Status: Assigned +Status: Bogus -Assigned To: quipo +Assigned To: danielc In SVN commit r328127, I added a testBug15232() method in tests/Standard/BugsTest.php. The test passes (I used mysql, mysqli, and pgsql) when running the against the beta release that came out yesterday (2.5.0b4). Not sure if the beta fixed the release the users are running or if there are overriding factors in the users' code or environment that are/were causing the problems. Marking this "bogus" so it doesn't show up as fixed when generating the next release.
encoded: -Status: Assigned +Status: Bogus -Assigned To: quipo +Assigned To: danielc In SVN commit r328127, I added a testBug15232() method in tests/Standard/BugsTest.php. The test passes (I used mysql, mysqli, and pgsql) when running the against the beta release that came out yesterday (2.5.0b4). Not sure if the beta fixed the release the users are running or if there are overriding factors in the users' code or environment that are/were causing the problems. Marking this "bogus" so it doesn't show up as fixed when generating the next release.
date: 2012-10-24T19:05:04+00:00

ghada [2011-09-05 00:16]
type: item
description: We're FINALLY migrating from DB to MDB2. We are now running into this same issue with the database connections. We have several database connections: 1. MSSQL - 2 connections to 2 different databases on the same box (DB1, DB2). 2. MySql - 1 connection to 1 database (DB3). 3. PgSql - 1 connection to 1 database (DB4). The MySql and the PgSql databases are on the same box. The MSSQL databases are on a different box to the MySql and PgSql databases. We've tried the 'new-link=true' on the DSN. We've tried using the: - factory() - connect() - singleton() None of them work when we switch between the databases. i.e. (this could be any query) 1. Run Query1 on MSSQL DB1 2. Run Query2 on MySql DB3 3. Run Query3 on MSSQL DB2 - this generates the error "MDB2 Error: no such table". We have the latest MDB2 (2.4.1) and php (5.3.1). Has this issue been resolved or is there some "trick" that we're missing?
encoded: We're FINALLY migrating from DB to MDB2. We are now running into this same issue with the database connections. We have several database connections: 1. MSSQL - 2 connections to 2 different databases on the same box (DB1, DB2). 2. MySql - 1 connection to 1 database (DB3). 3. PgSql - 1 connection to 1 database (DB4). The MySql and the PgSql databases are on the same box. The MSSQL databases are on a different box to the MySql and PgSql databases. We've tried the 'new-link=true' on the DSN. We've tried using the: - factory() - connect() - singleton() None of them work when we switch between the databases. i.e. (this could be any query) 1. Run Query1 on MSSQL DB1 2. Run Query2 on MySql DB3 3. Run Query3 on MSSQL DB2 - this generates the error "MDB2 Error: no such table". We have the latest MDB2 (2.4.1) and php (5.3.1). Has this issue been resolved or is there some "trick" that we're missing?
date: 2011-09-05T00:16:08+00:00

phreek_11 [2010-07-14 07:54]
type: item
description: Still doesnt work for me. I have persistent and new_link set to true. I have the latest MDB2 packages (with mssql) and PHP 5.2.5. When switching between 2 connections on 2 different servers it works fine, but when switching between two different databases on the same server (and different username/passwords) it does not work.
encoded: Still doesnt work for me. I have persistent and new_link set to true. I have the latest MDB2 packages (with mssql) and PHP 5.2.5. When switching between 2 connections on 2 different servers it works fine, but when switching between two different databases on the same server (and different username/passwords) it does not work.
date: 2010-07-14T07:54:25+00:00

alec [2010-06-10 14:40]
type: item
description: Works for me with "?new_link=true" added to $dsn2. Tested with pgsql driver and 2.4.1/2.5.0-svn versions. This ticket should be closed.
encoded: Works for me with "?new_link=true" added to $dsn2. Tested with pgsql driver and 2.4.1/2.5.0-svn versions. This ticket should be closed.
date: 2010-06-10T14:40:25+00:00

doconnor [2010-03-02 15:42]
type: item
description: I can't tell: is this because MDB2 uses a bunch of static methods and global state, or persistent connections causing global state behaviour ?
encoded: I can't tell: is this because MDB2 uses a bunch of static methods and global state, or persistent connections causing global state behaviour ?
date: 2010-03-02T15:42:51+00:00

c0ntax [2008-12-05 13:18]
type: item
description: Sorry to reopen this, but have a try of the script below with persistent connections set to true. Even with new_link=true in the DSN it still exhibits the same erronious behaviour of running the first query against the second database handle.
encoded: Sorry to reopen this, but have a try of the script below with persistent connections set to true. Even with new_link=true in the DSN it still exhibits the same erronious behaviour of running the first query against the second database handle.
date: 2008-12-05T13:18:55+00:00

quipo [2008-12-04 09:28]
type: item
description: http://pear.php.net/manual/en/package.database.mdb2.faq.php#package.database.mdb2.faq.twoinstances http://www.phpied.com/reusing-an-existing-database-connection-with-mdb2/
encoded: http://pear.php.net/manual/en/package.database.mdb2.faq.php#package.database.mdb2.faq.twoinstances http://www.phpied.com/reusing-an-existing-database-connection-with-mdb2/
date: 2008-12-04T09:28:45+00:00