Database transaction error handling |
I am aware of the discussions on this topic in the CI forum, StackOverflow and elsewhere. I tried to do my research carefully but it seems to me, that I did not find a proper answer.
The question is how to handle database transaction errors and not to loose the error details. The CI guide suggested way is PHP Code: $this->db->trans_start(); However if 'db_debug' in config/database.php is TRUE, the execution fails on the first failing query and the error handling code is never run. OK, so let's set 'db_debug' to FALSE. In this case the error handling code runs, but how do I find out more about the DB error (error code and message)? Again, the recommended way is to use $this->db->_error_message() and $this->db->_error_number(), but they return nothing when 'db_debug' is FALSE. And this is my problem. It is not enough to detect an error, I need to know more about it. I found only this solution to the problem, but I don't like it because it is quite verbose: PHP Code: try { Please not that - I am using the "manual transaction" mode of CI, - I have to call $this->db->_error_message(), $this->db->_error_number() after each query, because it returnes an ampty response in the catch block. Only this way I can achieve the detailed error handling but I find it clunky. Is there a more elegant way? Thank you |
Messages In This Thread |
Database transaction error handling - by RastoStric - 02-23-2015, 03:03 AM
RE: Database transaction error handling - by obiron - 02-24-2015, 08:06 AM
RE: Database transaction error handling - by RastoStric - 02-25-2015, 01:19 AM
RE: Database transaction error handling - by Shawn - 01-04-2017, 07:55 PM
|