Yii2: update field with query builder

arfname picture arfname · Aug 24, 2014 · Viewed 65.5k times · Source

How can I update field with query builder in Yii2? I can't find this in documentation.

Thanks!

UPD

This is the solution:

// UPDATE
$connection = Yii::$app->db;
$connection->createCommand()->update('user', ['status' => 1], 'age > 30')->execute();

Answer

Kshitiz picture Kshitiz · Aug 30, 2014

Create command can be used directly as follows :

\Yii::$app->db->createCommand("UPDATE table SET column1=:column1, column2=:column2 WHERE id=:id")
->bindValue(':id', your_id)
->bindValue(':column1', :column1_value)
->bindValue(':column2', :column2_value)
->execute();