I’ve looked through the numerous posts here on SO and Googled the heck out of this, but none of what I’ve unearthed yet has mentioned anything specific to my exact issue. So, please pardon the seeming redundant nature of this question.
I have a model that when it attempts to insert a record into a table and that insert violates unique value indexing I have on certain fields, CI throws up it’s own error message about the error.
I am wondering if there is a way to override CodeIgniter’s displayed errors it shows on database errors with my own handler so that instead of the user’s experience being totally ruined by an error, I can simply indicate to the user that what they submitted was a duplicate of something already in the database.
Now, I know I could do this by just running a select against the DB and handling it that way, but that seems totally counter-intuitive to the database’s own ability to be able to handle such things with unique indexes.
So, has anyone found a way to hook into the database error handling in CI and override it with their own implementations?
Check for an existing value before you submit your query, its not counter-intuitive. You should NEVER rely on the database to validate user/your input.. use PHP.