RecordSet::update - jcobban/Genealogy GitHub Wiki
$recordSet->update($setparms, $xml, $simulate, $order)
Up: class RecordSet
This method updates all of the records in the set and returns the number of records updated. If any unusual data is encountered it is reported by adding a message to $warn. A specific case is if the SET clause is empty because no valid parameters were passed in the first parameter. The parameters for this method are:
parameter | description |
---|---|
$setparms | An associative array of field name/value combinations to specify an update to be applied to all records belonging to this RecordSet. |
$xml | If boolean true or a string generate XML output to standard output. If a string then it is used to name the root tag, otherwise the root tag is <cmd>. |
$simulate | If true the database is not updated, although output specified by the $xml parameter is generated. |
$order | If the update must be performed in a particular order, this parameter specifies the contents of the ORDER BY clause. |
The value assigned to a fieldname in $setparms can be:
- "+=<integer>" add the integer to the field. The generated SET expression contains "`field`=`field`+?".
- "-=<integer>" subtract the integer from the field. The generated SET expression contains "`field`=`field`-?".
- array("from_str", "to_str") update the occurrences of the field by replacing "from_str" with "to_str". The SET expression contains "`field`=REPLACE(`field`,?,?)".
- Any simple value including strings not starting with "+=" or "-=", integers, numbers, or null. The SET expression contains "`field`=?".
The following changes the surname of everyone named Smith to Smythe.
$smiths = new RecordSet('Names',
array('surname' => 'Smith'));
$smiths->update(array('surname' => 'Smythe'));
Next: $recordset->getWhere()