Answer the question
In order to leave comments, you need to log in
How to accumulate data before writing to tables?
There is an array of rows - $rows, each row of the array is passed to the aggregator function.
public function uploader($rows)
{
foreach ($rows as $row => $data) {
$this->aggregator($data);
}
...
}
public function aggregator($data)
{
...
table1->column1=data[1];
...
table1->column10=date[10];
table1->save();
...
table2->column1=data[11];
table2->column2=table1->column3;
...
table2->save();
}
Answer the question
In order to leave comments, you need to log in
In the aggregator function, numerous actions are performed on each row, after which different parts of the rows are written to tables.
class MyClass
{
public function uploader($rows)
{
$items = [];
foreach ($rows as $row => $data) {
$items[] = $this->aggregator($data);
}
$this->save($items)
}
public function aggregator($data)
{
// выполнение нужных операций над данными
}
public function save($items)
{
// сохранение массива данных, аля batchInsert
}
}
Need some kind of batchInsert
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question