title: PHP PDO Call to a member function execute() on a non object
body: <p>So I'm using prepared statements to handle my JSON call from my cordova app to a database.</p>
  
  <p>Right now, I'm trying to get nearby locations based on <code>POST</code>ed latitude and longitude, but the prepared statement isn't working.</p>
  
  <p>When I set the variables to just test, I'm getting a <code>Call to a member function execute() on a non object</code> error.</p>
  
  <p>I don't know what I'm doing wrong!</p>
  
  <pre><code>    error_reporting(E_ALL);
  
      $lat = 42.35674265310388;
      $lon = -71.13770473755070;
      $miles = 5;
      //$lat = $_POST["lat"];
      //$lon = $_POST["lon"];
      $data = array();
  
      $sth = $mysqli-&gt;prepare('SELECT *, (3959 * acos(cos(radians(?)) * cos(radians(lat)) * cos(radians(lon) - radians(?)) + sin(radians(?)) * sin(radians(lat)))) AS distance FROM members WHERE (3959 * acos(cos(radians(?)) * cos(radians(lat)) * cos(radians(lon) - radians(?)) + sin(radians(?)) * sin(radians(lat)))) &lt; ? ORDER BY distance 5');
      $sth-&gt;execute(array($lat, $lon, $lat, $lat, $lon, $lat, $miles));
      $row = $sth-&gt;fetch();
  
      $data["markers"][] = array
      (
          "lat" =&gt; $row['lat'],
          "lon" =&gt; $row['lon']
      );
  
      print_r($data);
  
      echo json_encode($data);
  </code></pre>
  
  <p>Also, I <code>var_dump()</code>ed the <code>$lat</code> <code>$lon</code> and <code>$miles</code> variables, shown below.</p>
  
  <pre><code>lat - float(42.356742653104)
  lon - float(-71.137704737551)
  miles - int(5)
  </code></pre>