如果无法连接,我正试图阻止query
到数据库。
基本上,如果无法连接并且app_debug = false
它jusst会抛出500错误,如果app_debug = true
显示错误跟踪。
我需要当没有连接到DB时只返回一个空的array
到现在为止我试过这个:
foreach(config('some_config') as $v){
if(config('database.connections.'.$v)){{
if(DB::connection($v)->getDatabaseName()){
//ther is connection can query DB
}
//no connection next element
}
}
但是我仍然得到500错误,有什么建议吗? (laravel方式,不使用PDO or mysqli_connect
答案 0 :(得分:0)
使用@Helder Lucas推荐的try catch