...

View Full Version : mysql optimization



iGutman
07-16-2011, 06:57 PM
I have a DB table with more then 30,000 rows (users)

I use this SELECT statment to get name of user by id:


$result = $mysqli->query("SELECT name,last_name FROM users WHERE id=$id LIMIT 1");

while ($row = mysqli_fetch_assoc($result)){


$name=$row['name'];

$lastname=$row['last_name'];

} // while

mysqli_free_result($result);

I tried this also but I didnt saw any diffrent:


if($mysqli_result = $mysqli->query("SELECT name,last_name FROM users WHERE id=$id LIMIT 1")){

$result = $mysqli_result->fetch_row();

$name=$result[0];

$lastname=$result[1];

}
mysqli_free_result($mysqli_result);

But it take to long.. how can I optimize it to run faster?

oracleguy
07-16-2011, 11:32 PM
Is the ID column setup as the primary key for the table?

iGutman
07-17-2011, 08:40 AM
yes, id is my primary key.

guelphdad
07-17-2011, 04:37 PM
how long does the query take to run outside of PHP? figure out if there is a db problem before you find out if there is a PHP problem.

Looks straightforward and if ID has an index on it you should be talking fractions of a second. 30,000 rows is negligible in size.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum