メインコンテンツまでスキップ
Version: Fegg 5.x

Model::updateRow

連想配列で1行を更新します

説明​

public int Model::updateRow( array $row, mixed $id )

主キーが$idの行を更新し、更新した行数を返します(該当する行がなければ0)。渡したカラムだけを書き込み、nullはNULLとして保存します。modifiedは自動で入り、バインドの型変換も行います。

insertRowと同じ場合にInvalidArgumentExceptionを投げます。

引数​

名前データ型デフォルト備考
$rowarray値(column => value)
$idmixed更新する行の主キーの値

例​

Controller
$model = new Model(true, array(
'table' => 'cms_news',
'id' => 'news_id',
'visible' => 'visible',
));

// Only title (and modified) are written; the other columns keep their value
// Update "cms_news" Set "title"= 'New title', modified = '2026-11-09 17:40:25' Where news_id = 1
$updated = $model->updateRow(array('title' => 'New title'), 1);
// -> 1