This is a simple example of how to use Yii?s updateAll():
In this example we want to set conditions like status = 1 WHERE type_id = 1 AND status = 0
Note this is a simple example where we are only updating one column and using a string for our condition. There are more complex options available.
1 |
Comment::model()->updateAll(array( 'status' => 1 ), 'type_id = 1 AND status = 0 ' ); |
So as you can see first comes an array of column => new_value pairs, then a condition string which is pretty much used as the WHERE clause.
An example of updating more than one column:
1 |
Comment::model()->updateAll(array( 'status' => 1, 'updated' => '2011-08-25 09:33:23' ), 'type_id = 1 AND status = 0 ' ); |