PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Database » DB » Bug #6668

Error handling of Pear::DB (DB_Error)

Details

Submitted2006-02-02 13:54 UTC
Frompeter dot buki at vodafone dot hu
Assigneddanielc
StatusBogus
PackageDB
PHP Version5.0.5
OSSunOS 5.10 Generic sun4u
Roadmaps(Not assigned)

Comments

[2006-02-02 13:54 UTC] peter dot buki at vodafone dot hu

Description:
------------
I get the following error message when trying to use DB_Common::getAssoc or getAll
Fatal error: Call to undefined method DB_Error::getAssoc() in /home/peter.buki/public_html/warrant/dbtest.php on line 15

Fatal error: Call to undefined method DB_Error::getAll() in /home/peter.buki/public_html/warrant/dbtest.php on line 14

Test script:
---------------
<?PHP

require_once 'DB.php';

$dsn = "mysql://bukipeti:bukipeti@localhost/bukipeti" ;
$options = array(
'debug' => 2,
'portability' => DB_PORTABILITY_ALL,
);

$db =& DB::connect($dsn, $options);

$query="select USERNAME, PASSWORD from USER" ;
$result =& $db->getAll($query, false, array(), DB_FETCHMODE_OBJECT);
$result =& $db->getAssoc($query, false, array(), DB_FETCHMODE_OBJECT);

$db->disconnect ;

?>

Expected result:
----------------
Getting the array containing the results instead of this error message.

Actual result:
--------------
Fatal error: Call to undefined method DB_Error::getAssoc() in /home/peter.buki/public_html/warrant/dbtest.php on line 15
_or_
Fatal error: Call to undefined method DB_Error::getAll() in /home/peter.buki/public_html/warrant/dbtest.php on line 14

[2006-02-02 14:39 UTC] peter dot buki at vodafone dot hu

Please do not use the original example script.

Please fetch this one (using wget for example):
http://www.freeweb.hu/bukipeti/dbtest.txt

(sorry for sharing it as text/html, it works only this way)

[2006-02-03 09:49 UTC] peter dot buki at vodafone dot hu

Actually I have found the bug in my script. :-)
The dsn variable was empty. (defined $this->dsn and used $dsn)

But the problem of Pear::DB is that the error handling could have tell me that this is the problem.

So this (last:) example script:
<?PHP
require_once 'DB.php';
$db = DB::Connect($nonexistingvariable, array()) ; //No dsn specified
if (PEAR::isError($db))
{ die($db->getMessage()); }
?>

Will produce the following output:
DB Error: not found

I would expect something like "Error connecting" / "Invalid DSN".

Letting me know the alternate (more efficient) way of debugging the script would be highly appreciated :-)