I have a very simple question.
Is there any way to relate database errors to a well formed warning?
What I mean is for example a user is registering in a site and the username chosen by him/her is already been taken so when saving to the database the following error happens:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'peter' for key 'username'
I really don’t want to show this to the user but something more like:
“The chosen username has already been taken”
What’s the best way to identify the error and output a well formed warning?
Thanks in advance
You do a select query first to check if the username was taken. Only if it’s not do you insert it.
Ideally you lock the table, or use transactions, but practically it’s probably OK if the two queries are right near each other.