$campaigns
array of data:
[
...
27 => array:10 [
"name" => "0ca9b377dd066958_ru_acc9_map86"
"cid" => "53099327454745088"
"status" => 2
"id" => 36842
]
...
]
Prepare before update:
foreach ($campaigns as $campaign) {
$id = $campaign['campaign_id'];
$name = $campaign['name'];
$status = $campaign['status'];
$index = Campaign::getIndex($name);
$aSource = Campaign::aSource($name, $status);
$streamId = Campaign::getStreamIdByName($name);
$updateValues[] = [
'id' => $id,
'name' => $name,
'status' => $status,
'index' => $index,
'a_source' => $aSource,
'stream_id' => $streamId,
'updated_at' => new Expression('NOW()')
];
}
How can i do update all rows with id
in ids
from $campaigns
array with new values of name, status, index, a_source, stream_id
and updated_at
?
Help me please, i have tried all options from doc and chatGPT, like:
–batch insert
a) with `ON DUPLICATE KEY UPDATE`
b) and `ON CONFLICT (id) DO UPDATE SET`
2
Answers
I tried this way for now, and i will be grateful if you share your experience:
If number of rows of campaings is so huge, better fetching data in batches. It will give your memory/hardware resource usage under control.
https://www.yiiframework.com/doc/api/2.0/yii-db-query#batch()-detail