Pdo::setIncrement
Add to a numeric column in an UPDATE
Description
public self Pdo::setIncrement( string $column, int|float $by )
Adds "column" = "column" + ? to an update, so the addition happens in the database and simultaneous requests do not lose counts. Model::increment() uses it.
Throws InvalidArgumentException when $column is not a plain name or $by is not an int or a float.
Arguments
| Name | Data type | Default | Remarks |
|---|---|---|---|
| $column | string | Numeric column | |
| $by | int/float | Amount to add; negative to subtract |
Example
Controller
$db = new \Fegg\Database\Pdo();
// Update "cms_news" Set modified = ?, "view_count" = "view_count" + ? Where news_id = ?
$db->setIncrement('view_count', 1)->setWhere('news_id = ?', 5)->update('cms_news')->execute();