Quote:
Originally Posted by Dormilich
easiest and most failsafe method is making the username column either the Primary Key or UNIQUE.
|
I'm also going with this too
@LearningCoder, while selecting will work it's an extra query to run on the sql server. IF you get too many of those it will grind to a halt.
If you set the column to unique and try to insert an existing user, the sql server won't insert it. You can then test whether or not the user was inserted by using mysql_num_rows() which will tell you how many rows were inserted - of course if there were none due to the username already existing then it will be 0. This doesn't (afaik) run a second query on the server because mysql automatically counts the affected rows and returns it with each query and holds it in memory meaning that you don't need to run another query on the database files to get the number.