title: PHP PDO fetchAll then json_encode doesn't work
body: <p>I have a strange issue. I have a simple PHP script that uses PDO to get all countries from a database then returns the result as json. When I use the fetch function instead of fetchAll everything works as expected. When I print_r the data is there.</p>
  
  <p>Doesn't work:</p>
  
  <pre><code> $sql = "SELECT * FROM countries";
  if($stmt = $_db-&gt;prepare($sql))
  {
      $stmt-&gt;execute();
      $data = $stmt-&gt;fetchAll(PDO::FETCH_ASSOC);
      $stmt-&gt;closeCursor();
  
      header("content-type:application/json");
  
      echo json_encode($data);
      exit();
  
  }
  </code></pre>
  
  <p>Works: </p>
  
  <pre><code> $sql = "SELECT * FROM countries";
  if($stmt = $_db-&gt;prepare($sql))
  {
      $stmt-&gt;execute();
      $data = $stmt-&gt;fetch(PDO::FETCH_ASSOC);
      $stmt-&gt;closeCursor();
  
      header("content-type:application/json");
  
      echo json_encode($data);
      exit();
  
  }
  </code></pre>
  
  <p>Results of print_r:</p>
  
  <pre><code>Array
  (
  [0] =&gt; Array
      (
          [id] =&gt; 1
          [name] =&gt; Afghanistan
      )
  
  [1] =&gt; Array
      (
          [id] =&gt; 2
          [name] =&gt; Åland Islands
      )
  
  [2] =&gt; Array
      (
          [id] =&gt; 3
          [name] =&gt; Albania
      )
  ....
  [248] =&gt; Array
      (
          [id] =&gt; 249
          [name] =&gt; Zimbabwe
      )
  
  )
  1
  </code></pre>