Reputation: 401
So let's say a user registers for an account, I would like to check if the email being used is already associated with another account...
On the database side, I put a unique constraint on the email column. Now on the application side, should I run a query to check whether that email is already in use and then if it isn't, run another query to insert the user? Or should I ignore that step and since I already have a unique constraint in the database column, I should just attempt to insert the user and if I get an error, I know the email is already in use?
Is running a query just to check for the email being redundant or is it a necessary step and why?
I am using PHP and MySQL.
Upvotes: 0
Views: 72
Reputation: 39414
Yes, it's redundant, but you might want to do it.
You have two choices, really:
Depending upon the relative ease of these two approaches, decide which works for you.
Upvotes: 1