Welcome Guest, Not a member yet? Register   Sign In
Database transaction error handling
#3

Thank you for your comment. However I think that it would be quite the same as in my case; moreover for error handling I prefer exceptions. Anyway, your comment made me consider a possibility to wrap the CI database class so that it would use exceptions for error handling. Then the schema would be clean:
PHP Code:
try {
 $this->db->trans_begin();
 $this->db->query('AN SQL QUERY...');
 $this->db->query('ANOTHER QUERY...');
 $this->db->trans_commit();
}
catch (
Exception $e) {
 $this->db->trans_rollback();
 log_message('error'sprintf('%s : %s : DB transaction failed. Error no: %s, Error msg:%s, Last query: %s'__CLASS____FUNCTION__$e->getCode(), $e->getMessage(), print_r($this->main_db->last_query(), TRUE)));

The only problem is that the CI DB class cannot by extended... I'll have to think about it.
Thank you anyway.
Reply


Messages In This Thread
RE: Database transaction error handling - by RastoStric - 02-25-2015, 01:19 AM



Theme © iAndrew 2016 - Forum software by © MyBB