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

Model::updateWhere

条件に合う行を、列挙したカラムで更新します

説明​

public int Model::updateWhere( string $item, array $data, string $where, mixed $wh_data )

$whereに合うすべての行を更新し、更新した行数を返します。新しく書くコードではupdateRowsWhereを使ってください。updateWhere()は、$itemに指定したカラムのうち$dataにないものに''を書き込み、NULLを保存できません。

$wh_dataは1つの値、またはプレースホルダーごとに1つずつ値を並べた配列です。条件は必須です。$whereが空だとInvalidArgumentExceptionを投げます。本当にすべての行を更新するときは'1 = 1'を渡します。

引数​

名前データ型デフォルト備考
$itemstringカラム(カンマ区切り)
$dataarray値
$wherestring?プレースホルダーを使った条件
$wh_datamixedプレースホルダーに入れる値

例​

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->updateWhere($item, $data, 'category = ? AND news_id > ?', array(2, 10));