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_DataObject » Bug #2718

->update() method incorrectly returns false

Details

Submitted2004-11-08 16:04 UTC
Frombigtree at 29a dot nl
StatusBogus
PackageDB_DataObject
PHP Version4.3.9
OSwin xp
Roadmaps(Not assigned)

Comments

[2004-11-08 16:04 UTC] bigtree at 29a dot nl

Description:
------------
The update() method returns false, even when a record has actually been updated.

The version of DB_DataObject used is 1.7.2 (stable) on a factory default php install 4.3.9 (stable). The database used is MySQL 4.1.7-nt (stable).

According to the manual, update() should return the number of rows updated. However, it always returns false unless the (optional) parameter $original has been set. Even if a record has been updated (and the actual value has been changed in the database).

Workaround: The code that does produce the expected output is $tmpuser->update($tmpuser) instead of $tmpuser->update().

Reproduce code:
---------------
<?php
$tmpuser = new Auth_user(); // this is a DB_DataObject, autogenerated
$tmpuser->setUsername('someuser');
if ($tmpuser->find(true) == 1) {
$tmpuser->setPassword(md5(time())); // just an example to make sure we're updating the record
echo ($tmpuser->update() === false) ? 'ok' : 'not ok'; // this line always outputs 'not ok', even if the record has been changed in database
}
?>

[2004-12-11 13:18 UTC] bigtree at 29a dot nl

It's not a bug. ($tmpuser->update() === false) should return 'false' when the update() succeeded. Just a twist in bool logic. My bad.