Skip to main content
Version: Fegg 5.x (next)

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​

NameData typeDefaultRemarks
$itemstringColumns, separated by commas
$dataarrayValues
$idmixedTarget 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