📜  如何在 laravel 8 中捕获查询异常 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:53:58.680000             🧑  作者: Mango

代码示例1
try { 
  $results = \DB::connection("example")
    ->select(\DB::raw("SELECT * FROM unknown_table"))
    ->first(); 
    // Closures include ->first(), ->get(), ->pluck(), etc.
} catch(\Illuminate\Database\QueryException $ex){ 
  dd($ex->getMessage()); 
  // Note any method of class PDOException can be called on $ex.
}