Welcome Guest, Not a member yet? Register   Sign In
MySQL error messages
#1

[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.
#2

[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.
#3

[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.
#4

[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).




Theme © iAndrew 2016 - Forum software by © MyBB