CodeIgniter Forums
MySQL error messages - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: MySQL error messages (/showthread.php?tid=5187)



MySQL error messages - El Forum - 01-10-2008

[eluser]Unknown[/eluser]
I'm inserting to a table where I'm creating a key that I know will sometimes already exist. Is standard PHP I ignore error 1062 , but Codeigniter stops and diaplays an error for the duplicate. I can't see anything in the documentation to show how to handle any MySQL errors such as this.


MySQL error messages - El Forum - 01-10-2008

[eluser]xwero[/eluser]
You could set the error display off but without an error the user will think everything is ok so that's no solution.

Because the database class isn't extendable and the error isn't meant for the public i think it's best to use a try/catch block to intercept the error.

The easiest way is to prevent errors for example by checking if the key exists an generate another if it does.


MySQL error messages - El Forum - 01-10-2008

[eluser]eggshape[/eluser]
I don't think this is a CI problem. Such an error would occur if the key was identified as UNIQUE when the key was created. If you delete the key and recreate without the UNIQUE identifier, this should not be a problem.


MySQL error messages - El Forum - 01-11-2008

[eluser]gon[/eluser]
You could turn database debugging off, and check the result of the query command.
The command should return false on a UNIQUE key error (or any other error).