PHP 2 mysql merge results

I execute 2 queries on 2 different servers with the same table structure. How can I combine 2 arrays in PHP?

thanks

+3
source share
3 answers

PDO :: query () returns a PDOStatement that implements the Traversable interface .
The SPL class IteratorIterator wraps any Callbacks as an Iterator .
And another SPL class, AppendIterator , can "concatenate" iterators to act as one iterator.

<?php
$result1 = $pdo1->query('SELECT * FROM foo');
$result2 = $pdo2->query('SELECT * FROM foo');

$it = new AppendIterator;
$it->append(new IteratorIterator($result1));
$it->append(new IteratorIterator($result2));

foreach($it as $row) {
  echo join(', ', $row), "\n";
}
+4
source

array_merge.

array array_merge ( array $array1 [, array $... ] )

, . .

, . , , , , .

, .

+1

, , ( db auto_increment), UUID .

, uuid , , , , .

0
source

Source: https://habr.com/ru/post/1716144/


All Articles