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

Pdo::update

Set update query

Description​

public self Pdo::update( string $table )

Builds an UPDATE on $table from the values set with setValues (or setItem) and setIncrement, and the condition set with setWhere. modified is added unless given. Run it with execute and read the number of updated rows with getAffectedRow.

Unlike Model::updateRowsWhere(), Pdo does not refuse an UPDATE without a condition: without setWhere() every row is updated.

Arguments​

NameData typeDefaultRemarks
$tablestringTarget table name

Example​

Controller
$db = new \Fegg\Database\Pdo();

// Update "cms_news" Set "title"= ?, modified = ? Where news_id IN (?, ?)
$db->setValues(array('title' => 'New title'))
->setWhere('news_id IN (?)', array(1, 2))
->update('cms_news')
->execute();
$updated = $db->getAffectedRow();
// -> 2