Welcome Guest, Not a member yet? Register   Sign In
Should I check for errors after DB updates ?

I am currently checking for errors after I modify data in my DB. At the end of each of my functions in my models, I check if changes occured with a if ($this->db->affected_rows())

Should I be doing this, or does CodeIgniter's Database Class already verify for errors and I did not find about it ? If it does, how can I check for errors ?

Thank you.

Really, that's more for update and delete operations. If an entry can't be inserted, you'll probably be shown the database error page, which you have little control over.

Thanks for your response, but you are saying that there is no way if using Active Records to catch a DB error, and redirect the flow to a customized screen or error handling routine ?

Again, we have no option to implement something very basic like the old php:
mysql_query($sql1,$db) or die("Error message"); ?

It depends. The error messages that CodeIgniter would display automatically, are things like errors in syntax, or errors returned directly by the database platform. This is the way that the database library has been designed, but of course, there's nothing saying you have to use that at all. You can do it procedurally, or you can use another library, so yes, you can catch errors at that level, but only if you bypass the database library completely.

In essence, what I'm saying is that I personally only check for rows affected when I've done a delete or update operation. When I insert, it's generally only one row at a time, so if an error wasn't detected by the library, and displayed to the user, then we can assume our insert operation was successful.

Hopefully that makes sense.

Theme © iAndrew 2016 - Forum software by © MyBB