Home » Database » MDB2 » Bug #8337
connect(), factory() and singleton() return errors inconsistently
Details
| Submitted | 2006-08-01 12:55 UTC |
|---|---|
| From | erin dot millard at i-nex dot com dot au |
| Status | Bogus |
| Package | MDB2 |
| PHP Version | 5.1.4 |
| OS | Windows XP |
| Roadmaps | (Not assigned) |
Comments
[2006-08-01 12:55 UTC] erin dot millard at i-nex dot com dot au
Description:
------------
When creating an MDB2 instance using singleton() or factory() I found that so long as you provide a valid phptype in your DSN, PEAR::isError() and MDB2::isError() will not return true for the instance even if the rest of your DSN is wrong or invalid.
This seems to hold true when using any phptype and also when using an accociative array instead of a DSN string to connect.
connect() seems to work fine however. After a quick browse of MDB2.php, I fixed the problem on my system by moving the following section of code from connect() to factory():
$err = $db->connect();
if (PEAR::isError($err)) {
$dsn = $db->getDSN('string', 'xxx');
$db->disconnect();
$err->addUserInfo($dsn);
return $err;
}*/
I believe this may have been the intention anyway, as connect() and singleton() both internally use factory() to create the instance.
Test script:
---------------
<?php
require_once 'MDB2.php';
$mdb2_connect =& MDB2::connect('mysql://');
if (MDB2::isError($mdb2_connect)){
echo "connect() threw an error\n";
}
$mdb2_factory =& MDB2::factory('mysql://');
if (MDB2::isError($mdb2_factory)){
echo "factory() threw an error\n";
}
$mdb2_singleton =& MDB2::singleton('mysql://');
if (MDB2::isError($mdb2_singleton)){
echo "singleton() threw an error\n";
}
?>
Expected result:
----------------
connect() threw an error
factory() threw an error
singleton() threw an error
Actual result:
--------------
connect() threw an error
[2006-08-01 13:30 UTC] erin dot millard at i-nex dot com dot au
I can see how this behaviour would be useful in some cases, and if my understanding is flawed I apologise; but the Connect Introduction - which I had read before posting the bug, does not specifically say that you must connect() after using singleton() or factory().
If this is the case, then why does the following still not throw an error:
$mdb2_singleton =& MDB2::singleton('mysql://');
$mdb2_singleton->connect('mysql://');
And surely the next example is not correct either, as it would create a unique instance every time and negate the reason for using singleton() in the first place:
$mdb2_singleton =& MDB2::singleton('mysql://');
$mdb2_singleton =& MDB2::connect('mysql://');
Thanks for the prompt reply and once again I am sorry if this is not the proper channel for discussions of this nature.