如何在laravel中获取当前查询db\u host值

z6psavjg  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(362)

在此位置:..\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值呢?

epggiuax

epggiuax1#

env('DB_HOST_READ');
env('DB_HOST_WRITE');

相关问题