what takes the less resources

Codes here !

Moderators: egami, macek, gesf

Post Reply
*JaH*
New php-forum User
New php-forum User
Posts: 80
Joined: Fri Jan 31, 2003 4:18 pm

Wed Mar 05, 2003 10:06 pm

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 :)

User avatar
Redcircle
Moderator
Moderator
Posts: 826
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA
Contact:

Thu Mar 06, 2003 1:34 pm

$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
}

*JaH*
New php-forum User
New php-forum User
Posts: 80
Joined: Fri Jan 31, 2003 4:18 pm

Thu Mar 06, 2003 2:45 pm

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? :)

*JaH*
New php-forum User
New php-forum User
Posts: 80
Joined: Fri Jan 31, 2003 4:18 pm

Fri Mar 07, 2003 4:42 pm

so it's microtime() :D thanks alot! For some reason I couldn't find it anywhere on php :) thanks! :)

pootergeist
New php-forum User
New php-forum User
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK
Contact:

Sat Mar 08, 2003 2:50 am

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.
avatar image based upon nasas apod (only updates if I post though)

Post Reply
  • Information
  • Who is online

    Users browsing this forum: Bing [Bot] and 2 guests