title: PDO fetchObject() after fetchall(). returning false
body: <p>I am new to PHP.
  I am trying to display the details of employees in form of table.
  But <code>while($row = $result-&gt;fetchObject())</code> part is not executing, as <code>$result-&gt;fetchObject()</code> is returning false. Has it something to do with <code>$rows = $result-&gt;fetchAll();</code>?
  Here's the code snippet.</p>
  
  <pre><code>$sql = "SELECT id, name, designation FROM employees";
  
  if ($result = $pdo-&gt;query($sql)) {
      $rows = $result-&gt;fetchAll();
      $num_rows = count($rows);
  
      if ($num_rows &gt; 0) {
          echo "&lt;table&gt;\n";
          echo " &lt;tr class=\"heading\"&gt;\n";
          echo " &lt;td&gt;ID&lt;/td&gt;\n";
          echo " &lt;td&gt;Name&lt;/td&gt;\n";
          echo " &lt;td&gt;Designation&lt;/td&gt;\n";    
          echo " &lt;/tr&gt;\n";
  
          while($row = $result-&gt;fetchObject()) {
              echo " &lt;tr&gt;\n";
              echo " &lt;td&gt;" . $row-&gt;id . "&lt;/td&gt;\n";
              echo " &lt;td&gt;" . $row-&gt;name . "&lt;/td&gt;\n";
              echo " &lt;td&gt;" . $row-&gt;designation . "&lt;/td&gt;\n";
              echo " &lt;/tr&gt;\n";
          }
          echo "&lt;/table&gt;";
      } else {
          echo "No employees in database.";
      }
  
  else {
      echo "ERROR: Could not execute $sql. " . print_r
      ($pdo-&gt;errorInfo());
  }
  </code></pre>