wshaman
(Rakoth Android)
1
Hello, yiiers!
Does anyone know if there is a way to make a query with DAO?
UPDATE my_table SET int_field = int_field + 1;
So I want to increment some field like this:
(new Query())->createCommand()->update(
MyTable::tableName(),
['int_field' => 'int_field +1']
)->execute();
And this way is totally wrong because of value converting to integer.
Is raw sql the only option?
Try this:
(new Query())->createCommand()->update(
MyTable::tableName(),
['int_field' => new Expression("int_field + 1")]
)->execute();
Bizley
(Bizley)
3
Bizley
(Bizley)
5
Oh, right. AR method is helpful and exactly this but not what op wanted. Sorry.
Like this?
Yii::$app->db->createCommand('UPDATE my_table SET int_field = int_field+1')->execute();
If not, where are you trying to execute the sql and what is the purpose?
wshaman
(Rakoth Android)
7
Thanks! It seems that’s the thing I’m looking for!