流明数据库[xxx]未配置

时间:2015-08-21 16:15:15

标签: php laravel lumen

我正在尝试使用Lumen查询我的一个设置数据库。我创建了一个这样的配置文件:

配置/ database.php中

return [
    'mysql' => [
        'domains' => [
            'host'     => 'localhost',
            'username' => 'root',
            'password' => '',
            'database' => 'domains'
        ],
        // Other connections here...
        'driver'  => 'mysql'
    ]
];

然后我尝试在我的路线中执行我的查询

应用/ HTTP / routes.php文件

$app->get('/billing/saved/{id}', function($id){
    $data = DB::connection('domains')
            ->select('select billing_id, nickname
                from billing
                where user_id = 108649 and billing_id = ?', [$id]);
    return response()->json($data);
});

当它运行时,我收到以下错误消息:

InvalidArgumentException in DatabaseManager.php line 238:
Database [domains] not configured.

in DatabaseManager.php line 238
at DatabaseManager->getConfig('domains') in DatabaseManager.php line 157
at DatabaseManager->makeConnection('domains') in DatabaseManager.php line 67
at DatabaseManager->connection('domains') in Facade.php line 210
at Facade::__callStatic('connection', array('domains')) in routes.php line 68
at DB::connection('domains') in routes.php line 68
at Closure->{closure}('1')
at call_user_func_array(object(Closure), array('1')) in Container.php line 502
at Container->call(object(Closure), array('id' => '1')) in Application.php line 1263
at Application->callActionOnArrayBasedRoute(array('1', array(object(Closure)), array('id' => '1'))) in Application.php line 1237
at Application->handleFoundRoute(array('1', array(object(Closure)), array('id' => '1'))) in Application.php line 1211
at Application->handleDispatcherResponse(array('1', array(object(Closure)), array('id' => '1'))) in Application.php line 1163
at Application->Laravel\Lumen\{closure}() in Application.php line 1390
at Application->sendThroughPipeline(array(), object(Closure)) in Application.php line 1164
at Application->dispatch(null) in Application.php line 1104
at Application->run() in index.php line 28

我做错了什么?

1 个答案:

答案 0 :(得分:1)

我知道您已经找到了答案,但这可能有助于其他用户遇到相同问题或寻找正确的设置。

return ['connections' => [
  'mysql' => [
        'driver'    => 'mysql',
        'host'      => 'localhost',
        'database'  => 'db_name',
        'username'  => 'user',
        'password'  => 'db_password',
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
        'strict'    => false,
    ]
  ]
]