2015-08-21 65 views
1

我想用流明查詢我的一個設置數據庫。我創造了這樣的一個配置文件:流明數據庫[xxx]未配置

的config/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

沒有真正使用流明,但通過一些快速閱讀,應該'mysql'字符串'連接'和'驅動程序'行在'域'內? –

+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, 
    ] 
    ] 
] 
+0

這完全沒有幫助。我看到這是來自'config/database.php'。我從.env文件導入了我的信息,但除此之外,它是相同的。但是,如果我將會話驅動程序設置爲文件,那麼它可以工作,如果是數據庫,則不會。我勒個去? – Bert