int $DB_DataObject->update (
dataobject|boolean $original|$useWhere
)
Updates current objects variables into the database. if you supply it with a dataObject, as an argument, it will only update the differences between the new and old.
if called with DB_DATAOBJECT_WHEREADD_ONLY as the argument, the update request is built based on the whereAdd values, rather than the primary key. This enables global updates to be performed, rather than single row ones.
DataObject $original
-
if provided the update query will be built from the difference between the current and
original dataobject.
int
number of rows affected or FALSE on failure
Error code | Error message | Meaning | Solution |
---|---|---|---|
DB_DATAOBJECT_ERROR_INVALIDCONFIG | "update:No table definition for $table" | ||
DB_DATAOBJECT_ERROR_NODATA | "update: No Data specifed for query $settings" |
This function can not be called statically.
Simple fetch and update
<?php
$person = new DataObjects_Person;
$person->get(12);
$person->name='fred';
$person->update();
$person = new DataObjects_Person;
$person->get(12);
$original = clone($person); // clone is emulated in php4 for compatibility reasons.
$person->name='fred';
$person->update($original);
?>
Resulting SQL
Simple fetch and update
<?php
$person = new DataObjects_Person;
$person->removed=1;
$person->whereAdd('age > 21');
$person->update();
?>
Resulting SQL