所以我想从两个mysql数据库中获取数据。默认情况下,您在.env文件和config / database.php上定义一个。
我现在想要添加另一个外部数据库。我怎样才能做到这一点?我可以在.env和config / database.php中定义两个或更多数据库吗?
任何人的帮助。谢谢: -
答案 0 :(得分:1)
你是怎么做到的:
# 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.