使用try-catch

try{
if($result==false){
throw new \Exception("错误提示信息");
}
$data['status'] = "200";
$data['message'] = "SUCCESS";
}
catch(\Exception $e){
$data['status'] = "201";
$data['message'] = $e->getMessage();
}
return $data;
tp事物处理(多个增加和保存)
try{
$Model = M();
$Model->startTrans();
if($result==false){
throw new \Exception("错误提示信息");
}
$Model->commit();
$data['status'] = "200";
$data['message'] = "SUCCESS";
}
catch(\Exception $e){
$Model->rollback();
$data['status'] = "201";
$data['message'] = $e->getMessage();
}
return $data;

 

你可能感兴趣的:(PHP)