To compare two tables from different databases using cursor(), you can use the following code:
$fields = collect(DB::
connection($database_1)
->select('describe '.$table))
->map(function ($item) {
return $item->Field;
});
$datas_1 = DB::
connection($database_1)
->table($table)
->orderByDesc('id')
->limit(100000)
->cursor();
$datas_2 = DB::
connection($database_2)
->table($table)
->orderByDesc('id')
->cursor();
foreach ($datas_1 as $key => $datas_1_item) {
$diff = false;
foreach ($fields as $field) {
if ($field != 'time_execution') {
$datas_2_item = $datas_2->next();
if ($datas_1_item->$field != $datas_2_item->$field) {
$diff = true;
...
}
}
}
}
In this code, we are using cursor() to retrieve the data from both tables. We are looping over the data from the first table using foreach loop. Inside the loop, we are using next() method to get the next item from the second table. We are then comparing the fields of both items. If there is a difference, we are setting the $diff variable to true.