我想定製或處理codeigniter中的查詢錯誤刪除,但問題是它不起作用。 如何使用try catch或else語句處理它?如何在刪除錯誤時在codeigniter中捕獲數據庫錯誤?
控制器:
public function delete($id){
$this->load->model('m_customer_info');
$delete=$this->m_customer_info->delete_data($id);
$this->get_all_customers();
}
型號:
public function delete_data($id){
$delete="delete from member where idno='$id'";
try{
$this->db->query($delete);
}
catch(Exception $e)
{
echo "<script>alert('Cannot delete because it is a club officer')</script>";
}
/*if($delete==true){
$this->db->query($delete);
}
else
echo "<script>alert('Cannot delete because it is a club officer')</script>";
*/
}
檢查[this](http://stackoverflow.com/questions/9093334/codeigniter-db-delete-returns-true-always)q/a。 – Tpojka