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

Model::updateRowsWhere

Update the rows matching a condition from an associative array

Description​

public int Model::updateRowsWhere( array $row, string $where, [ mixed $params = [] ] )

Updates every row matching $where and returns the number of updated rows. Columns are written as in updateRow. $params works as in where: one value, or an array of values in placeholder order (an array on a single IN (?) placeholder expands it).

The condition is required: an empty $where throws InvalidArgumentException. Pass '1 = 1' to really update every row. Conditions chained with where are not used.

Arguments​

NameData typeDefaultRemarks
$rowarrayValues (column => value)
$wherestringCondition with ? placeholders
$paramsmixed[]One value, or an array of values in placeholder order

Example​

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

// Hide every news of category 3
$updated = $model->updateRowsWhere(array('visible' => 0), 'category = ?', 3);

$updated = $model->updateRowsWhere(array('category' => 1), 'news_id IN (?)', array(4, 5, 6));

// Every row
$updated = $model->updateRowsWhere(array('visible' => 1), '1 = 1');