By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,964 Members | 1,810 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,964 IT Pros & Developers. It's quick & easy.

MySQL timing out when selecting one record out of 9 million

P: 20
Hi, I just uploaded 9 million records to a mysql table. The table consists of an id, a name, and a numeric value. The way its supposed to work is that the user passes the name to php and php returns the numeric value. However, either mysql or php is timing out -- I think. Here's what I've got so far:

Expand|Select|Wrap|Line Numbers
  1. $query = "SELECT `value` FROM `table` WHERE `name` = '$q' LIMIT 1";
  2.  
  3. $result = mysql_query($query) or die(mysql_error());
  4.  
  5. mysql_close($dbhandle);
  6.  
  7. if($result)
  8. {
  9.     if(!$row = mysql_fetch_array($result))
  10.     {
  11.         //STILL SHOWS UP HERE
  12.         //no value
  13.     }
  14.     else
  15.     {
  16.         //value
  17.     }
  18. }
  19. else
  20. {
  21.  
  22.     //no value
  23. }
  24.  
When the query is called and times out, mysql still returns an empty row. Is there anyway to optimize the query or anything else I can do to retrieve the records? Thanks in advanced!
Mar 23 '10 #1
Share this Question
Share on Google+
2 Replies


jkmyoung
Expert 100+
P: 2,057
Sorry, just to make sure: Have you been able to retrieve any other records from this table with a more defined search? If there are 9 million records you may need to give it more time to search.
Mar 23 '10 #2

P: 20
Hi, yeah, I've been able to load other records. It seems to be fine loading the records with a higher index. When I try to load the first row, I get the problem of the empty result. In my file, I have code that will fire when the empty row is returned, so I know that's where my issues are.
Mar 23 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.