Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

what takes the less resources

Codes here !

Moderators: macek, egami, gesf

what takes the less resources

Postby *JaH* » 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 :)
*JaH*
New php-forum User
New php-forum User
 
Posts: 80
Joined: Fri Jan 31, 2003 4:18 pm

Postby Redcircle » 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
}
User avatar
Redcircle
Moderator
Moderator
 
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

Postby *JaH* » 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

Postby jetthe » Fri Mar 07, 2003 3:28 pm

*JaH* wrote:but what is the function to show how many milliseconds it takes to parse the script? :)


i'm dealing with that the "lame" way as some have told me,
i'm starting the page(or rather the first inclusion file) with:

$starttime = microtime();
(to feeeed it)

the ends by printing:

echo "page generated in ";
echo array_sum(explode(' ', microtime())) - array_sum(explode(' ', $starttime)) . ' seconds';


greets[/code]
jetthe
New php-forum User
New php-forum User
 
Posts: 3
Joined: Sun Mar 02, 2003 8:15 am

Postby *JaH* » 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! :)
*JaH*
New php-forum User
New php-forum User
 
Posts: 80
Joined: Fri Jan 31, 2003 4:18 pm

Postby pootergeist » 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.
pootergeist
New php-forum User
New php-forum User
 
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK


Return to mySQL & php coding

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.