2016-11-23 1 views
1

Also würde ich gerne Daten aus zwei MySQL-Datenbank erhalten. Standardmäßig definieren Sie eine .env-Datei und auch config/database.php.Wie erhalten Daten aus zwei Datenbanken in Laravel 5.3?

Ich möchte jetzt eine weitere externe Datenbank hinzufügen. Wie kann ich das erreichen? Kann ich zwei oder mehr Datenbanken in .env und config/database.php definieren?

Jeder Hilfe. Vielen Dank: -

Antwort

1

Das ist, wie Sie es tun:

# Knust primary database connection 
'mysql' => [ 
    'driver' => 'mysql', 
    'host'  => env('DB_HOST', 'localhost'), 
    'database' => 'hofsa_knust', 
    'username' => 'root', 
    'password' => '', 
    'charset' => 'utf8', 
    'collation' => 'utf8_unicode_ci', 
    'prefix' => '', 
    'strict' => false, 
], 

     # Legon primary database connection 
    'mysql2' => [ 
    'driver' => 'mysql', 
    'host'  => env('DB_HOST', 'localhost'), 
    'database' => 'hofsa_legon', 
    'username' => 'root', 
    'password' => '', 
    'charset' => 'utf8', 
    'collation' => 'utf8_unicode_ci', 
    'prefix' => '', 
    'strict' => false, 
], 

This is a good tutorial on how to use miltiple databases in laravel.

+0

Dank ... Ich bin jetzt auf der wissen. –