php try catch 检查数据库主键重复

来源:互联网 发布:js金额格式化 编辑:程序博客网 时间:2024/06/03 04:55

php try catch  检查数据库主键重复

try {   

$res= $model->save(); 
} catch (Exception $e) 
{   
 if(strpos($e->getMessage(), "Duplicate entry") !== false)
 print_r(json_encode('插入数据重复'));
  exit();  
}