He there!
I was wondering if there is a function in the Yii framework that allows you to multiply or divide all rows in a database. I know there is the updateAll function, that allows you to change values and updateCounters that allow you to add/subtract a number to all like this:
Items::model()->updateAll(array( 'tokens' => 5 ), '' );
Items::model()->updateCounters(array('tokens' => -5,), '');
But what I want to do, is multiply the value by 1.5. I tried different things, but unfortunately I cannot seem to get it work..
Items::model()->updateCounters(array('tokens' => * 1.5,), '');
Items::model()->updateAll(array( 'tokens' => 'tokens*1.5' ), '' );
Would be great if someone could help me find a solution.
尝试将表达式包装在CDbExpression中
Items::model()->updateAll(array( 'tokens' => new CDbExpression('tokens*1.5')));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.