Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 2.5.0b5

Request #10537 Improve testing of index keys in singleton()
Submitted: 2007-03-28 11:10 UTC
From: fornax Assigned: fornax
Status: Closed Package: MDB2 (version 2.4.0)
PHP Version: 4.3.11 OS: Centos 4.3, Apache 1.3
Roadmaps: (Not assigned)    

 [2007-03-28 11:10 UTC] fornax (Andrew Hill)
Description: ------------ I've seen some external packages (eg. WACT) set the database connection to NULL when disconnecting from a database. As a result, the value that MDB2 expects to be in $GLOBALS['_MDB2_databases'] may not be there anymore, and errors result! Below is a small patch which improves the MDB2 singleton() method by adding a test to ensure that the expected previous singleton connection is still present when creating a connection. Hope it helps! Test script: --------------- --- MDB2.php (revision 5433) +++ MDB2.php (working copy) @@ -485,10 +485,12 @@ $dsninfo = array_merge($GLOBALS['_MDB2_dsninfo_default'], $dsninfo); $keys = array_keys($GLOBALS['_MDB2_databases']); for ($i=0, $j=count($keys); $i<$j; ++$i) { - $tmp_dsn = $GLOBALS['_MDB2_databases'][$keys[$i]]->getDSN('array'); - if (count(array_diff($tmp_dsn, $dsninfo)) == 0) { - MDB2::setOptions($GLOBALS['_MDB2_databases'][$keys[$i]], $options); - return $GLOBALS['_MDB2_databases'][$keys[$i]]; + if (isset($GLOBALS['_MDB2_databases'][$keys[$i]])) { + $tmp_dsn = $GLOBALS['_MDB2_databases'][$keys[$i]]->getDSN('array'); + if (count(array_diff($tmp_dsn, $dsninfo)) == 0) { + MDB2::setOptions($GLOBALS['_MDB2_databases'][$keys[$i]], $options); + return $GLOBALS['_MDB2_databases'][$keys[$i]]; + } } } } elseif (is_array($GLOBALS['_MDB2_databases']) && reset($GLOBALS['_MDB2_databases'])) {


 [2007-03-28 16:15 UTC] quipo (Lorenzo Alberton)
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on by the end of next Sunday (CET). If this was a problem with the website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.