I have project on Yii2. I have 2 databases. I need to execute command with join like
SELECT * FROM `table1` LEFT JOIN `table2` ON `table1`.`id` = `table2`.`id`;
..where table1 is from db1 and table2 from db2. notice: db2 is on another server.
'db1' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=db1',
'username' => '...',
'password' => '...',
'charset' => 'utf8',
],
'db2' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=anotherserver.com;dbname=db2',
'username' => '...',
'password' => '...',
'charset' => 'utf8',
]
Q1: How to do that on clean mysql/php? on Yii2?
.. or the only way is to fetch results from table1 and table2 separated and then loop to compare id?
Q2: How to compare id in yii2 in dataProvider?
$query = Table1::find();
$query2 = Table2::find();
// how compare id?
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
