Model::update
Execute Update the record by specified primary ID
Description
public int Model::update( string $item, array $data, mixed $id )
Updates the row whose primary key is $id and returns the number of updated rows. For new code, use updateRow: update() writes '' for every column listed in $item that is missing from $data, and cannot store NULL. modified is set automatically and bind types are applied.
Arguments
| Name | Data type | Default | Remarks |
|---|---|---|---|
| $item | string | Columns, separated by commas | |
| $data | array | Values | |
| $id | mixed | Target primary ID |
Example
Controller
$model = new Model(true, array(
'table' => 'cms_news',
'id' => 'news_id',
'visible' => 'visible',
));
$item = 'title, content';
$data = array(
'title' => 'Sample title',
'content' => 'Sample content',
);
$updated = $model->update($item, $data, 1);
// -> 1