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 #4461

Suggestion for warning about incorrect use of getOne

Details

Submitted2005-05-28 11:39 UTC
Fromoracle dot shinoda at gmail dot com
StatusWont fix
PackageDB
PHP Version4.3.11
OSDebian Linux
Roadmaps(Not assigned)

Comments

[2005-05-28 11:39 UTC] oracle dot shinoda at gmail dot com

Description:
------------
I was working with the DB package trying to get it to insert some data. But because I didn't realise that using getOne was wrong to do this, I was attempting to use getOne (and getRow) to run these queries. What actually happened was that the script encountered a fatal error inside the getOne method. This was because the query was run and had DB_OK returned, which getOne promptly tried to call fetchInto on.

Now I know that this was a silly thing to do and I now use query(), but perhaps a warning in the documentation about this caveat would be a good thing for anyone else using it. It certainly would have saved me an evening debugging my script.

Alternatively, you could make the getOne and other methods check for DB_OK as well, but I guess that isn't really a good call.

Reproduce code:
---------------
<?php

// Assume DB object is in $db...
$res = $db->getOne("INSERT INTO table VALUES ('blah')"); // fatal error

?>

Expected result:
----------------
No behaviour change, just a change in the documentation.