在此位置:..\config\database.php
'mysql' => [
'read' => [
'host' => env('DB_HOST_READ', '127.0.0.2'),
],
'write' => [
'host' => env('DB_HOST_WRITE', '127.0.0.1'),
],
'driver' => 'mysql',
// 'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
添加的.env文件:
DB_HOST_READ=127.0.0.2
DB_HOST_WRITE=127.0.0.1
查看读写主机值。我想验证用于当前运行的读写查询的主机。
我用的是Laravel5.5。那么,如何为每个查询获取db\u host值呢?
1条答案
按热度按时间epggiuax1#