From:  pear-qa@lists.php.net ("joel@inflatableoffice.com")
Date:  23 Oct 2015 20:07:02 Hong Kong Time
Newsgroup:  news.php.net/php.pear.bugs
Subject:  

[PEAR-BUG] Bug #12395 [Com]: singleton() with multiple databases results in errors in certain circumstances

NNTP-Posting-Host:  null

Edit report at https://pear.php.net/bugs/bug.php?id=12395&edit=1

 ID:               12395
 Comment by:       joel@inflatableoffice.com
 Reported By:      mdcore at gmail dot com
 Summary:          singleton() with multiple databases results in errors
                    in certain circumstances
 Status:           Closed
 Type:             Bug
 Package:          MDB2
 Operating System: Ubuntu edgy
 Package Version:  2.4.1
 PHP Version:      5.1.6
 Assigned To:      quipo
 Roadmap Versions: 
 New Comment:

I'm having this same problem. new_link=true does solve the issue, but
multiple calls to the code  will open multiple connections to the same
db, which is the primary reason for using Singleton.


Previous Comments:
------------------------------------------------------------------------

[2007-11-07 11:08:25] quipo

Have you tried with the "new_link" DSN setting?
http://pear.php.net/manual/en/package.database.mdb2.intro-dsn.php

------------------------------------------------------------------------

[2007-11-07 10:25:42] mdcore

Description:
------------
Basically I have db1=singleton(dsn1) and db2=singleton(dsn2)

db1->query() works
then db2->query() works
then db1->query() fails

Test script:
---------------
 'mysql', 'username' => 'dev', 'password' =>
'dev', 'hostspec' => 'localhost', 'database' => 'db1');
$dsn2 = array( 'phptype' => 'mysql', 'username' => 'dev', 'password' =>
'dev', 'hostspec' => 'localhost', 'database' => 'db2');

$db1 =& MDB2::singleton($dsn1);
$db2 =& MDB2::singleton($dsn2); 

$result = $db1->query('SELECT * FROM db1_table');
if (MDB2::isError($result)) { throw new
Exception($result->getMessage().' - '.$result->getUserinfo()); die(); }

$result = $db2->query('SELECT * FROM db2_table');
if (MDB2::isError($result)) { throw new
Exception($result->getMessage().' - '.$result->getUserinfo()); die(); }

$result = $db1->query('SELECT * FROM db1_table');
if (MDB2::isError($result)) { throw new
Exception($result->getMessage().' - '.$result->getUserinfo()); die(); }
?>

Expected result:
----------------
no error

Actual result:
--------------
Fatal error Uncaught exception 'Exception' with message 'MDB2 Error: no
such table - _doQuery: [Error message: Could not execute statement]
[Last executed query: SELECT * FROM db1_table] [Native code: 1146]
[Native message: Table 'db2.db1_table' doesn't exist] ' in
/home/gavin/public_html/testing/mdb2_singleton_test.php:18 Stack trace:
#0 {main} thrown in
/home/gavin/public_html/testing/mdb2_singleton_test.php on line 18

------------------------------------------------------------------------


-- 
Edit this bug report at https://pear.php.net/bugs/bug.php?id=12395&edit=1