Skip to main content
Version: Fegg 5.x

Model::deleteWhere

Delete the rows matching a condition (soft delete)

Description​

public int Model::deleteWhere( string $where, mixed $data )

Soft-deletes every row matching $where (sets valid = 0) and returns the number of updated rows. $data is one value, or an array with one value per placeholder.

The condition is required: an empty $where throws InvalidArgumentException. Pass '1 = 1' to really delete every row.

Arguments​

NameData typeDefaultRemarks
$wherestringCondition with ? placeholders
$datamixedValues for the placeholders

Example​

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

$deleted = $model->deleteWhere('category = ?', 1);

// Every row
$deleted = $model->deleteWhere('1 = 1', array());