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();
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();
Try like this,
For Example,
Query builder is for select queries only (sum, max, count too). You should use other methods - AR or raw queries (https://github.com/yiisoft/yii2/blob/master/docs/guide/db-dao.md#basic-sql-queries)
**this is the right syntax and works & tested in yii2 **
Also, if you need to use the column itself in the update query, you must use yii\db\Expression.
Create command can be used directly as follows :