View Full Version : mysql optimization

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



} // while


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();




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

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

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

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.