Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating multiple rows using Yii's updateAll()

Tags:

php

yii2

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().

like image 419
Turbo Host Avatar asked Sep 25 '22 19:09

Turbo Host


1 Answers

Active directory pattern. Good to write mode.

$movies_updated = SomeModel::updateAll([
     'language' => 'pl',
     'age' => 3,
], ['id' => 1]); # condition
like image 114
Rafal Avatar answered Oct 11 '22 12:10

Rafal