<?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/6226/bug">
    <title>PEAR Bug #6226</title>
    <link>http://pear.php.net/bugs/6226</link>
    <description>[Closed] Loading mysql driver fails</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/6226"/>
      <rdf:li rdf:resource="http://pear.php.net/bugs/6226/2005-12-13+05%3A28%3A08#2005-12-13+05%3A28%3A08"/>
      <rdf:li rdf:resource="http://pear.php.net/bugs/6226/2005-12-12+12%3A36%3A23#2005-12-12+12%3A36%3A23"/>
      <rdf:li rdf:resource="http://pear.php.net/bugs/6226/2005-12-12+12%3A04%3A42#2005-12-12+12%3A04%3A42"/>
      <rdf:li rdf:resource="http://pear.php.net/bugs/6226/2005-12-12+11%3A20%3A49#2005-12-12+11%3A20%3A49"/>
      <rdf:li rdf:resource="http://pear.php.net/bugs/6226/2005-12-12+08%3A47%3A37#2005-12-12+08%3A47%3A37"/>
      <rdf:li rdf:resource="http://pear.php.net/bugs/6226/2005-12-12+08%3A43%3A28#2005-12-12+08%3A43%3A28"/>
      <rdf:li rdf:resource="http://pear.php.net/bugs/6226/2005-12-12+07%3A57%3A42#2005-12-12+07%3A57%3A42"/>
      <rdf:li rdf:resource="http://pear.php.net/bugs/6226/2005-12-12+07%3A16%3A46#2005-12-12+07%3A16%3A46"/>
      <rdf:li rdf:resource="http://pear.php.net/bugs/6226/2005-12-12+06%3A41%3A39#2005-12-12+06%3A41%3A39"/>
     </rdf:Seq>
    </items>
  </channel>
    <item rdf:about="http://pear.php.net/bugs/6226">
      <title>petra.arentzen@... [2005-12-12 06:39:31]</title>
      <link>http://pear.php.net/bugs/6226</link>
      <description><![CDATA[<pre>MDB2_Driver_mysqli Bug
Reported by petra.arentzen@...
2005-12-12T11:39:31-00:00
PHP: 4.3.10 OS: Linux debian 2.6.14 Package Version: 

Description:
------------
MDB2                      2.0.0beta6 beta  
MDB2_Driver_mysql         0.1.1      beta  
  
  
Loading of mysql.php fails if &quot;MDB2.php&quot; is included by 
include-path, because there is a test if include-file  
&quot;MDB2/Driver/mysql.php&quot; exists. Because the script's 
current directory isn't PEAR's main directory (which is in 
include-path) this must fail and MDB2::factory() will 
return an error. 
 
Maybe this problem applies to other drivers too. 
 

Test script:
---------------
&lt;?
// from liveuser example5
require_once 'MDB2.php';

$dsn = 'mysql://testuser:testpassword@localhost/testdatabase';

$options = array(
    'portability' =&gt; (MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_EMPTY_TO_NULL),
want to use DB as the backend
);

$dsn = MDB2::parseDSN($dsn);
$database = $dsn['database'];
unset($dsn['database']);

$manager =&amp; MDB2_Schema::factory($dsn, $options);

?&gt;

Commenting out line 317 - 321 in &quot;MDB2.php&quot; solves the problem.


Expected result:
----------------
$manager should be a valid MDB2 Object   

Actual result:
--------------
$manager is an Error Object</pre>]]></description>
      <content:encoded><![CDATA[<pre>MDB2_Driver_mysqli Bug
Reported by petra.arentzen@...
2005-12-12T11:39:31-00:00
PHP: 4.3.10 OS: Linux debian 2.6.14 Package Version: 

Description:
------------
MDB2                      2.0.0beta6 beta  
MDB2_Driver_mysql         0.1.1      beta  
  
  
Loading of mysql.php fails if &quot;MDB2.php&quot; is included by 
include-path, because there is a test if include-file  
&quot;MDB2/Driver/mysql.php&quot; exists. Because the script's 
current directory isn't PEAR's main directory (which is in 
include-path) this must fail and MDB2::factory() will 
return an error. 
 
Maybe this problem applies to other drivers too. 
 

Test script:
---------------
&lt;?
// from liveuser example5
require_once 'MDB2.php';

$dsn = 'mysql://testuser:testpassword@localhost/testdatabase';

$options = array(
    'portability' =&gt; (MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_EMPTY_TO_NULL),
want to use DB as the backend
);

$dsn = MDB2::parseDSN($dsn);
$database = $dsn['database'];
unset($dsn['database']);

$manager =&amp; MDB2_Schema::factory($dsn, $options);

?&gt;

Commenting out line 317 - 321 in &quot;MDB2.php&quot; solves the problem.


Expected result:
----------------
$manager should be a valid MDB2 Object   

Actual result:
--------------
$manager is an Error Object</pre>]]></content:encoded>
      <dc:date>2005-12-12T11:39:31-00:00</dc:date>
    </item>
    <item rdf:about="http://pear.php.net/bugs/6226/2005-12-13+05%3A28%3A08#2005-12-13+05%3A28%3A08">
      <title>lsmith [2005-12-13 10:28]</title>
      <link>http://pear.php.net/bugs/6226#1134469688</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.

Well looking at it, it seems to make more sense to do the fileExists() check if the include failed, since the entire purpose is to determine the proper error message (file missing or file has parse errors). This should even speed things up a bit when loading drivers.

However there is another use case where I cannot do without fileExists() and that is in the loadModule() method. The problem is that some modules are backend specific and some are not:

MDB2_Extended

vs.

MDB2_Driver_Datatype_mysql

Since I do not want to make the user think about this, I check if the given file exists for once case and if it does not try the other case in order to determine what file to include and how to load the instance.

I will add a parameter for the user to hint this in loadModule() if they are in the unfortunate situation of safe_mode ..</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.

Well looking at it, it seems to make more sense to do the fileExists() check if the include failed, since the entire purpose is to determine the proper error message (file missing or file has parse errors). This should even speed things up a bit when loading drivers.

However there is another use case where I cannot do without fileExists() and that is in the loadModule() method. The problem is that some modules are backend specific and some are not:

MDB2_Extended

vs.

MDB2_Driver_Datatype_mysql

Since I do not want to make the user think about this, I check if the given file exists for once case and if it does not try the other case in order to determine what file to include and how to load the instance.

I will add a parameter for the user to hint this in loadModule() if they are in the unfortunate situation of safe_mode ..</pre>]]></content:encoded>
      <dc:date>2005-12-13T10:28:08-00:00</dc:date>
    </item>
    <item rdf:about="http://pear.php.net/bugs/6226/2005-12-12+12%3A36%3A23#2005-12-12+12%3A36%3A23">
      <title>petra.arentzen@... [2005-12-12 17:36]</title>
      <link>http://pear.php.net/bugs/6226#1134408983</link>
      <description><![CDATA[<pre>Ok, thank you. I think I can live with that.</pre>]]></description>
      <content:encoded><![CDATA[<pre>Ok, thank you. I think I can live with that.</pre>]]></content:encoded>
      <dc:date>2005-12-12T17:36:23-00:00</dc:date>
    </item>
    <item rdf:about="http://pear.php.net/bugs/6226/2005-12-12+12%3A04%3A42#2005-12-12+12%3A04%3A42">
      <title>lsmith [2005-12-12 17:04]</title>
      <link>http://pear.php.net/bugs/6226#1134407082</link>
      <description><![CDATA[<pre>I fear I will probably not be able to help you. I do not see another way of implementing the functionality I want (differentiate between file missing and file has parse errors). I will investigate but since you are the first user that experienced this and since it seems that safe_mode is on its way out (its likely to be dropped with php6 at the latest) I am relunctant to drop this feature. I may consider making it optional during debug mode only, but I will need to ponder it.</pre>]]></description>
      <content:encoded><![CDATA[<pre>I fear I will probably not be able to help you. I do not see another way of implementing the functionality I want (differentiate between file missing and file has parse errors). I will investigate but since you are the first user that experienced this and since it seems that safe_mode is on its way out (its likely to be dropped with php6 at the latest) I am relunctant to drop this feature. I may consider making it optional during debug mode only, but I will need to ponder it.</pre>]]></content:encoded>
      <dc:date>2005-12-12T17:04:42-00:00</dc:date>
    </item>
    <item rdf:about="http://pear.php.net/bugs/6226/2005-12-12+11%3A20%3A49#2005-12-12+11%3A20%3A49">
      <title>petra.arentzen@... [2005-12-12 16:20]</title>
      <link>http://pear.php.net/bugs/6226#1134404449</link>
      <description><![CDATA[<pre>Your hint about safe_mode leads me some steps further.    
I've debugged my script again and again. The problem seems    
to be the PHP-function is_readable(). Here's what I  
figured out:    
    
safe_mode off/ user: petra - works fine    
safe_mode  on/ user: petra - fails    
safe_mode  on/ user: root  - workes fine    
    
This seems to be very similar to the following bug   
http://bugs.php.net/bug.php?id=31618    
This bug was reported for php 5 cvs version.   
   
Perhaps it's an old bug which had survived since   
4.3.10 or even earlier.   
   
So it seems not to be a problem of MDB2. But perhaps it  
makes sense to remove calling fileExists().</pre>]]></description>
      <content:encoded><![CDATA[<pre>Your hint about safe_mode leads me some steps further.    
I've debugged my script again and again. The problem seems    
to be the PHP-function is_readable(). Here's what I  
figured out:    
    
safe_mode off/ user: petra - works fine    
safe_mode  on/ user: petra - fails    
safe_mode  on/ user: root  - workes fine    
    
This seems to be very similar to the following bug   
http://bugs.php.net/bug.php?id=31618    
This bug was reported for php 5 cvs version.   
   
Perhaps it's an old bug which had survived since   
4.3.10 or even earlier.   
   
So it seems not to be a problem of MDB2. But perhaps it  
makes sense to remove calling fileExists().</pre>]]></content:encoded>
      <dc:date>2005-12-12T16:20:49-00:00</dc:date>
    </item>
    <item rdf:about="http://pear.php.net/bugs/6226/2005-12-12+08%3A47%3A37#2005-12-12+08%3A47%3A37">
      <title>lsmith [2005-12-12 13:47]</title>
      <link>http://pear.php.net/bugs/6226#1134395257</link>
      <description><![CDATA[<pre>This is the implementation if fileExists(). I do not see anything that would cause your issues.

    function fileExists($file)
    {
        $dirs = explode(PATH_SEPARATOR, ini_get('include_path'));
        foreach ($dirs as $dir) {
            if (is_readable($dir . DIRECTORY_SEPARATOR . $file)) {
                return true;
            }
        }
        return false;
    }

The test is not useless, because it makes it possible to differentiate between the non existance of the file and a parse error in the file. I have also never ever had a single bug report on this piece of code. It also used in LiveUser. So it seems there is something in your environment thats &quot;non standard&quot;. Maybe some wierd safe mode setup?</pre>]]></description>
      <content:encoded><![CDATA[<pre>This is the implementation if fileExists(). I do not see anything that would cause your issues.

    function fileExists($file)
    {
        $dirs = explode(PATH_SEPARATOR, ini_get('include_path'));
        foreach ($dirs as $dir) {
            if (is_readable($dir . DIRECTORY_SEPARATOR . $file)) {
                return true;
            }
        }
        return false;
    }

The test is not useless, because it makes it possible to differentiate between the non existance of the file and a parse error in the file. I have also never ever had a single bug report on this piece of code. It also used in LiveUser. So it seems there is something in your environment thats &quot;non standard&quot;. Maybe some wierd safe mode setup?</pre>]]></content:encoded>
      <dc:date>2005-12-12T13:47:37-00:00</dc:date>
    </item>
    <item rdf:about="http://pear.php.net/bugs/6226/2005-12-12+08%3A43%3A28#2005-12-12+08%3A43%3A28">
      <title>petra.arentzen@... [2005-12-12 13:43]</title>
      <link>http://pear.php.net/bugs/6226#1134395008</link>
      <description><![CDATA[<pre>And I don't understand why you don't understand.      
It's not the first time I am using PEAR. I worked e.g with      
DB, DB_DataObject for more than three years. I'm sure that      
my Include-Path ist set correctly. No other pear      
application had ever had trouble with it.       
It seems that the (imho) useless test for the existence of 
the file before including it causes the trouble.    
So if I comment out this test the code works.     
In this case the code with      
the    
&lt;code&gt;    
if (!include_once($file_name)) {  
&lt;/code&gt; 
works fine because my include-path is set correcly.   
   
Now I've told all I can tell about this bug/ trouble/   
problem and if you are telling me further that it is my   
fail then I can't change it.   
  
I've tried my very best ;-)</pre>]]></description>
      <content:encoded><![CDATA[<pre>And I don't understand why you don't understand.      
It's not the first time I am using PEAR. I worked e.g with      
DB, DB_DataObject for more than three years. I'm sure that      
my Include-Path ist set correctly. No other pear      
application had ever had trouble with it.       
It seems that the (imho) useless test for the existence of 
the file before including it causes the trouble.    
So if I comment out this test the code works.     
In this case the code with      
the    
&lt;code&gt;    
if (!include_once($file_name)) {  
&lt;/code&gt; 
works fine because my include-path is set correcly.   
   
Now I've told all I can tell about this bug/ trouble/   
problem and if you are telling me further that it is my   
fail then I can't change it.   
  
I've tried my very best ;-)</pre>]]></content:encoded>
      <dc:date>2005-12-12T13:43:28-00:00</dc:date>
    </item>
    <item rdf:about="http://pear.php.net/bugs/6226/2005-12-12+07%3A57%3A42#2005-12-12+07%3A57%3A42">
      <title>lsmith [2005-12-12 12:57]</title>
      <link>http://pear.php.net/bugs/6226#1134392262</link>
      <description><![CDATA[<pre>I really dont understand what you are doing, but for PEAR to work the PEAR path needs to be in the include path and it is your job to ensure that no files collide with PEAR if the PEAR dir is not the first in the include path. There is nothing I can do about this.</pre>]]></description>
      <content:encoded><![CDATA[<pre>I really dont understand what you are doing, but for PEAR to work the PEAR path needs to be in the include path and it is your job to ensure that no files collide with PEAR if the PEAR dir is not the first in the include path. There is nothing I can do about this.</pre>]]></content:encoded>
      <dc:date>2005-12-12T12:57:42-00:00</dc:date>
    </item>
    <item rdf:about="http://pear.php.net/bugs/6226/2005-12-12+07%3A16%3A46#2005-12-12+07%3A16%3A46">
      <title>petra.arentzen@... [2005-12-12 12:16]</title>
      <link>http://pear.php.net/bugs/6226#1134389806</link>
      <description><![CDATA[<pre>Of course I had installed the mysql driver. The problem 
ist not that the include does not work - it's the test if 
the file exists before including it. The include would 
work but the code will not be executed because the 
previous test failes. 
 
/usr/share/php/MDB2.php: 
    function &amp;factory($dsn, $options = false) 
    { 
        $dsninfo = MDB2::parseDSN($dsn); 
        if (!array_key_exists('phptype', $dsninfo)) { 
            $err =&amp; MDB2::raiseError(MDB2_ERROR_NOT_FOUND, 
                null, null, 'no RDBMS driver specified'); 
            return $err; 
        } 
        $class_name = 'MDB2_Driver_'.$dsninfo['phptype']; 
 
        if (!class_exists($class_name)) { 
            $file_name = str_replace('_', 
DIRECTORY_SEPARATOR, $class_name).'.php'; 
#            if (!MDB2::fileExists($file_name)) { 
#                $err =&amp; 
MDB2::raiseError(MDB2_ERROR_NOT_FOUND, null, null, 
#                    'unable to find: '.$file_name); 
#                return $err; 
#            } 
            if (!include_once($file_name)) { 
                $err =&amp; 
MDB2::raiseError(MDB2_ERROR_NOT_FOUND, null, null, 
                    'unable to load driver class: '.
$file_name); 
                return $err; 
            } 
        } 
 
        $db =&amp; new $class_name(); 
        $db-&gt;setDSN($dsninfo); 
        $err = MDB2::setOptions($db, $options); 
        if (PEAR::isError($err)) { 
            return $err; 
        } 
 
        return $db; 
    } 
 
The lines with the leading '#' which I have filled in on 
my local file are causing the trouble.</pre>]]></description>
      <content:encoded><![CDATA[<pre>Of course I had installed the mysql driver. The problem 
ist not that the include does not work - it's the test if 
the file exists before including it. The include would 
work but the code will not be executed because the 
previous test failes. 
 
/usr/share/php/MDB2.php: 
    function &amp;factory($dsn, $options = false) 
    { 
        $dsninfo = MDB2::parseDSN($dsn); 
        if (!array_key_exists('phptype', $dsninfo)) { 
            $err =&amp; MDB2::raiseError(MDB2_ERROR_NOT_FOUND, 
                null, null, 'no RDBMS driver specified'); 
            return $err; 
        } 
        $class_name = 'MDB2_Driver_'.$dsninfo['phptype']; 
 
        if (!class_exists($class_name)) { 
            $file_name = str_replace('_', 
DIRECTORY_SEPARATOR, $class_name).'.php'; 
#            if (!MDB2::fileExists($file_name)) { 
#                $err =&amp; 
MDB2::raiseError(MDB2_ERROR_NOT_FOUND, null, null, 
#                    'unable to find: '.$file_name); 
#                return $err; 
#            } 
            if (!include_once($file_name)) { 
                $err =&amp; 
MDB2::raiseError(MDB2_ERROR_NOT_FOUND, null, null, 
                    'unable to load driver class: '.
$file_name); 
                return $err; 
            } 
        } 
 
        $db =&amp; new $class_name(); 
        $db-&gt;setDSN($dsninfo); 
        $err = MDB2::setOptions($db, $options); 
        if (PEAR::isError($err)) { 
            return $err; 
        } 
 
        return $db; 
    } 
 
The lines with the leading '#' which I have filled in on 
my local file are causing the trouble.</pre>]]></content:encoded>
      <dc:date>2005-12-12T12:16:46-00:00</dc:date>
    </item>
    <item rdf:about="http://pear.php.net/bugs/6226/2005-12-12+06%3A41%3A39#2005-12-12+06%3A41%3A39">
      <title>lsmith [2005-12-12 11:41]</title>
      <link>http://pear.php.net/bugs/6226#1134387699</link>
      <description><![CDATA[<pre>The drivers are no longer part of the core package. You need to install them separately:

pear install MDB2_Driver_mysql-beta</pre>]]></description>
      <content:encoded><![CDATA[<pre>The drivers are no longer part of the core package. You need to install them separately:

pear install MDB2_Driver_mysql-beta</pre>]]></content:encoded>
      <dc:date>2005-12-12T11:41:39-00:00</dc:date>
    </item>
</rdf:RDF>