Laravel 5.4上的多个数据库SQL服务器连接错误

时间:2017-04-26 09:25:14

标签: laravel laravel-5 laravel-5.2 laravel-5.3

error image

在我的数据库配置文件中 - 可能是app / config / database.php。

 'connections' => [

        'sqlsrv' => [
            'driver' => 'sqlsrv',
            'host' => env('DB_HOST', '192.168.0.5'),//'ADMINRG-2UH26BG', // Provide IP address here
            'database' => env('DB_DATABASE', 'VHPDEV'),
            'username' => env('DB_USERNAME', 'sa'),
            'password' => env('DB_PASSWORD', 'Dbp@2013'),
            'prefix' => '',
        ],
        'sqlsrv2' => [
            'driver' => 'sqlsrv',
            'host' => env('DB_HOST', '192.168.0.5'),//'ADMINRG-2UH26BG', // Provide IP address here
            'database' => env('DB_DATABASE', 'OCSDB'),
            'username' => env('DB_USERNAME', 'sa'),
            'password' => env('DB_PASSWORD', 'Dbp@2013'),
            'prefix' => '',
        ],

    ],

.ENV

DB_CONNECTION=sqlsrv
DB_HOST=192.168.0.5
DB_PORT=3306
DB_DATABASE=VHPDEV
DB_USERNAME=sa
DB_PASSWORD=Dbp@2013

查询

DB::connection('sqlsrv')->table('B14SILHOLD')->get();

1 个答案:

答案 0 :(得分:1)

你可以通过运行命令来清除laravel的缓存,例如: - php artisan config:cache并尝试执行它。 还要记住检查您的数据库是否在您使用它的模型中定义,或者只是放置\ DB :: connection('sqlsrv') - > table('B14SILHOLD') - > get();