title: How does PHP PDO::query actually do?
body: <p>Bit of confusion about what PDO::query does. Fully understand the difference between it and a prepare and execute, however it is unclear about if query runs a fetch. According to PHP.net:</p>
  
  <blockquote>
    <p>PDO::query — Executes an SQL statement, returning a result set as a PDOStatement object</p>
  </blockquote>
  
  <p>which is proven by:</p>
  
  <pre><code>$s = $pdo-&gt;query('SELECT * FROM user');
  var_dump($s);
  </code></pre>
  
  <p>which outputs:</p>
  
  <pre><code>object(PDOStatement)#2 (1) {
    ["queryString"]=&gt; string(18) "SELECT * FROM user"
  }
  </code></pre>
  
  <p>So its clearly giving us a PDOStatement object ready to run fetch or fetchAll on. HOWEVER. Take the following code taken from the PHP.net manual:</p>
  
  <pre><code>$sql = 'SELECT name, color, calories FROM fruit ORDER BY name';
  foreach ($conn-&gt;query($sql) as $row) {
      print $row['name'] . "\t";
      print $row['color'] . "\t";
      print $row['calories'] . "\n";
  }
  </code></pre>
  
  <p>This indicates that running a PDO::query actually runs a fetch internally and returns a result (which is mentioned in the initial description for the method). However if that is true then a subsequent call to fetch should return the second row, however it does not, you still get the first row.</p>
  
  <p>Does query run a fetch and reset the pointer so a subsequent fetch also returns the first row? if so, is this not unperformant? and why can you loop query and get multiple rows? does it run some kind of coroutine using yield? Additionally, why can you not see the fetched data in the PDOStatement object? Presumerably they are hiding this data using the __set_state and __debugInfo magic methods</p>