php - can't catch exception in codeIgniter -
sorry english please need have problem when i'm trying catch insert query
i have table employe 3 primary keys (matricule , cin , name)
i want catch exception when add new employe duplicated values
my model
function insert_employe($donnees){ try{ $this->db->insert('employe',$donnees); return 'employe enregistré avec succes'; }catch(exception $e) { return $e->getmessage(); } }
my controller
function nouveau(){ if(!$this->offres->_islogged() || !$this->input->post('ajax')==1){ redirect(base_url().'users'); } $values = $this->_get_values(); try{ $message = $this->employe->insert_employe($values); echo $message; }catch(exception $e){ echo $e->getmessage(); } }
i can't catch exception
this never throw exception:
$this->db->insert('employe',$donnees);
so you'll never catch exception that. if insert() method fails generate display custom error if $db['default']['db_debug']
set true on database.config or return false otherwise.
your best bet check errors when doing db operations:
$error = $this->db->_error_message() if(!empty($error)) { throw new exception('your message'); }
Comments
Post a Comment