<?xml version="1.0"?>
<?xml-stylesheet 
 href="http://www.w3.org/2000/08/w3c-synd/style.css" type="text/css"
?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel rdf:about="http://pear.php.net/bugs/10537/bug">
    <title>PEAR Bug #10537</title>
    <link>http://pear.php.net/bugs/10537</link>
    <description>[Closed] Improve testing of index keys in singleton()</description>
    <dc:language>en-us</dc:language>
    <dc:creator>pear-webmaster@lists.php.net</dc:creator>
    <dc:publisher>pear-webmaster@lists.php.net</dc:publisher>
    <admin:generatorAgent rdf:resource="http://pear.php.net/bugs"/>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <sy:updateBase>2000-01-01T12:00+00:00</sy:updateBase>
    <items>
     <rdf:Seq>
      <rdf:li rdf:resource="http://pear.php.net/bugs/10537"/>
      <rdf:li rdf:resource="http://pear.php.net/bugs/10537/2007-03-28+12%3A15%3A57#2007-03-28+12%3A15%3A57"/>
     </rdf:Seq>
    </items>
  </channel>
    <item rdf:about="http://pear.php.net/bugs/10537">
      <title>fornax</title>
      <link>http://pear.php.net/bugs/10537</link>
      <description><![CDATA[<pre>MDB2 Feature/Change Request
Reported by fornax
2007-03-28T12:10:17-00:00
PHP: 4.3.11 OS: Centos 4.3, Apache 1.3 Package Version: 2.4.0

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&lt;$j; ++$i) {
-                $tmp_dsn = $GLOBALS['_MDB2_databases'][$keys[$i]]-&gt;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]]-&gt;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']) &amp;&amp; reset($GLOBALS['_MDB2_databases'])) {</pre>]]></description>
      <content:encoded><![CDATA[<pre>MDB2 Feature/Change Request
Reported by fornax
2007-03-28T12:10:17-00:00
PHP: 4.3.11 OS: Centos 4.3, Apache 1.3 Package Version: 2.4.0

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&lt;$j; ++$i) {
-                $tmp_dsn = $GLOBALS['_MDB2_databases'][$keys[$i]]-&gt;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]]-&gt;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']) &amp;&amp; reset($GLOBALS['_MDB2_databases'])) {</pre>]]></content:encoded>
      <dc:date>2007-03-28T12:10:17-00:00</dc:date>
    </item>
    <item rdf:about="http://pear.php.net/bugs/10537/2007-03-28+12%3A15%3A57#2007-03-28+12%3A15%3A57">
      <title>quipo [2007-03-28 17:15]</title>
      <link>http://pear.php.net/bugs/10537#1175102157</link>
      <description><![CDATA[<pre>This bug has been fixed in CVS.

If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET).

If this was a problem with the pear.php.net 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.</pre>]]></description>
      <content:encoded><![CDATA[<pre>This bug has been fixed in CVS.

If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET).

If this was a problem with the pear.php.net 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.</pre>]]></content:encoded>
      <dc:date>2007-03-28T17:15:57-00:00</dc:date>
    </item>
</rdf:RDF>