I'm trying to update multiple rows in Yii:
$list = array(1, 2, 3, 4, 5);
foreach($list as $id) {
$query = "UPDATE products SET photos=crawler.photos, status=crawler.status WHERE id=crawler.product_id AND crawler.product_id=$id;";
}
I'm new to Yii. Basically, I want to update rows from table products
with the values from table scrape
(using specific id
, which are coming from $list
). But not with foreach()
, but with updateAll()
.
Active directory pattern. Good to write mode.
$movies_updated = SomeModel::updateAll([
'language' => 'pl',
'age' => 3,
], ['id' => 1]); # condition
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With