laravel 流明数据库 [xxx] 未配置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32145002/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 12:14:04  来源:igfitidea点击:

Lumen Database [xxx] not configured

phplaravellumen

提问by Get Off My Lawn

I am trying to query one of my setup databases with Lumen. I created a configuration file like this:

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

config/database.php

配置/数据库.php

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

I then try to execute my query in my route like this

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

app/Http/routes.php

应用程序/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);
});

When it gets run, I get the following error message:

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

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

What am I doing incorrectly?

我做错了什么?

采纳答案by mdamia

I know you already figured out the answer, though this might help other users having the same issue or looking for the correct settings.

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

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