title: MySQL vs PHP query performance issues
body: <p>I have a sql query that runs in like 2 seconds in mysql (Navicat) and it runs through 600,000 locations returning all the table data and calculates the distance between a lat and long that I put in.</p>
  
  <p>The SQL is something like this:</p>
  
  <pre><code>select *, 3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) * cos( radians( lng ) - 
  radians(-122) ) + sin( radians(37) ) * sin( radians( lat ) ) ) ) AS distance 
  FROM places 
  GROUP BY places.user_id
  HAVING distance &gt; 0
  ORDER BY distance LIMIT 0 , 10;
  </code></pre>
  
  <p>In the above query 37 and -122 are passed into the query as lat and long.</p>
  
  <p>When I run this in Navicat, it's 2 seconds, but it takes minutes in Cakephp or straight php using mysql_query().</p>
  
  <p>Why does this occur and how do I fix it?</p>
  
  <p>I'm running both MySQL and Apache locally on a Win7 4GB box running XAMPP.</p>