title: PHP: What's the fastest way to query MySQL? Because PDO is painfully slow
body: <p>I need to perform a simply query. </p>
  
  <p>Literally, all I need to perform is:</p>
  
  <pre><code>SELECT price, sqft, zipcode FROM homes WHERE home_id = X
  </code></pre>
  
  <p>When I use PHP <strong>PDO</strong>, which I've read is the recommended way to connect to a MySQL database, simply creating the connection takes a measured <strong>610ms</strong>.</p>
  
  <p>My code is below:</p>
  
  <pre><code>try {
      $conn_str = DB . ':host=' . DB_HOST . ';dbname=' . DB_NAME;
      $dbh = new PDO($conn_str, DB_USERNAME, DB_PASSWORD);
      $params = array();    
      $sql = 'SELECT price, sqft, zipcode FROM homes WHERE home_id = :home_id';
      $params[':home_id'] = X;
      $stmt = $dbh-&gt;prepare($sql);    
      $stmt-&gt;execute($params);
      $result_set = $stmt-&gt;fetchAll(PDO::FETCH_ASSOC);
      // json output  
      ob_start("ob_gzhandler");
      header('Content-type: text/javascript; charset=utf-8');
      print "{'homes' : ";
      print json_encode( $result_set );
      print '}';
      ob_end_flush();
      $dbh = null;
  } catch (PDOException $e) {
      die('Unable to connect');
  }
  </code></pre>
  
  <p><strong>Question</strong>: What's the fastest way for me to connect to my MySQL database to perform the query above?</p>