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

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.

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.

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.

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