在我的Laravel 5.5应用程序中,对Postgresql数据库运行select查询的DB :: select调用失败,而不显示Apache或Laravel错误日志中的任何错误,并触发"连接已重置"消息.此代码示例按预期运行,因为该函数get_users_with_roles存在.
public function missing_function(Request $request) {
try{
$all = DB::select('SELECT * from get_users_with_roles()', []);
}catch(Illuminate\Database\QueryException $qe){
return json_encode($qe->getMessage());
}
return json_encode($all);
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我用不存在的函数替换该SQL字符串:
public function missing_function(Request $request) {
try{
$all = DB::select('SELECT * from test()', []);
}catch(Illuminate\Database\QueryException $qe){
return json_encode($qe->getMessage());
}
return json_encode($all);
}
Run Code Online (Sandbox Code Playgroud)
连接被重置,我在日志中看不到任何错误.如果我在本机Postgresql环境中运行此错误查询:
SELECT * from test();
Run Code Online (Sandbox Code Playgroud)
我收到一条明确的错误消息:
ERROR: function test() does not exist
LINE 1: select * from test()
^
HINT: No function matches the given name and argument types. You might …Run Code Online (Sandbox Code Playgroud) 干草我正在创建这样的代码:
\Log::info("saving log....");
try{
$data = AstronautCandidateLog::insert($request->logs);
}catch (SQLException $e)
{
\Log::info("SQL Exception happened");
}catch (Exception $e)
{
\Log::info("Exception happened");
}
\Log::info("status save data : ". $data);
Run Code Online (Sandbox Code Playgroud)
但是似乎我的Exception从未被击中。那么,当sql查询出现问题时,如何在laravel中捕获异常?
提前致谢。