mercredi 8 décembre 2021

How to join Multiple databases from different hosts in Laravel

Is there any way to use join query with Multiple databases from different servers?

my database.php is

'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'db1'),
            'username' => env('DB_USERNAME', 'root'),
            'password' => env('DB_PASSWORD', ''),
            ...
        ],

        'mysql2' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST_2', '192.233.****.*'),
            'port' => env('DB_PORT_2', '3306'),
            'database' => env('DB_DATABASE_2', 'db2'),
            'username' => env('DB_USERNAME_2', 'root'),
            'password' => env('DB_PASSWORD_2', ''),
         ...
        ]

and i need to implement it in join query.

My controller function is

public function function1(){
$db1 = DB::connection('mysql2');
$result = TABLE1::join($db1 . '.' . 'table2', 'table2.id','=','table1.table2_id');

return Datatables::of($result);

}


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3IuDZDW
via IFTTT

Aucun commentaire:

Enregistrer un commentaire