what takes the less resources

A

Anonymous

Guest
I'm rewriting a whole website...and now I came a cross a little piece that I have to verify if a username already exists or not. The website has got more than 25000 members...what takes less resources:

to just select 'em all in one query or to only select the ones that start with the first letter of the username in question? (e.g. a%)?

Does anyone know how I could test these things? How to find out how much cpu power/memory it uses :) It's a massive website so it's really important that it uses as less possible :)
 
$query = 'select username from users where username = "'.$username"';
$result = mysql_query($query);
if(mysql_num_rows($result))
{
echo 'User Exists';
}
else
{
//add user code goes here
}
 
oh yeah...hmm stupid :D very very :) ah well, it was late ;) thx mate :)

but what is the function to show how many milliseconds it takes to parse the script? :)
 
so it's microtime() :D thanks alot! For some reason I couldn't find it anywhere on php :) thanks! :)
 
you could just make mysql do the hard work and set the username field to UNIQUE - that way, trying to insert a new row fails and you can output an error. Saves having to do any select before the insert = less queries = good.
 
Back
Top