title: PHP pagination fetchAll() and LIMIT
body: <p>This code work well on first page, but seems that LIMIT don't affect FetchAll().
  So my question is:
  Do fetchAll() have some optional argument that limit number of rows?
  Or suggest my a better way to solve this problem.</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  &lt;?php
  require_once('connection.php');
  $rowsCount = $connection-&gt;query('SELECT COUNT(*) FROM test')-&gt;fetchColumn();
  $page = 1;
  $perPage = 10;
  if ( isset( $_GET["page"] ) and $_GET["page"] &gt;= 1 and $_GET["page"] &lt;= 10 ) {
      $page = (int) $_GET["page"];
    }
  $beginning = ($page-1) * $perPage;
  $end = $page * $perPage;
  $sql = "SELECT * FROM test LIMIT $beginning, $end";
  
  ?&gt;
  &lt;table border = '2'&gt;
  &lt;tr&gt;
      &lt;th width="30%"&gt;ID&lt;/th&gt;
      &lt;th width="70%"&gt;TEXT&lt;/th&gt;
  &lt;/tr&gt;
  &lt;?php
  // echo '&lt;pre&gt;';
  // print_r($connection-&gt;query($sql)-&gt;fetch());
  // echo $sql;
  // echo '&lt;pre&gt;';
  foreach ($connection-&gt;query($sql) as $value) {
      echo '&lt;tr height ="50px"&gt;&lt;td&gt;' . $value['id'] . '&lt;/td&gt;&lt;td&gt;' .   $value['text'] . '&lt;/td&gt;&lt;/tr&gt;';
  }
  ?&gt;
  &lt;/table&gt;
      &lt;p&gt;
      &lt;?php if($page &gt; 1){ ?&gt;
          &lt;a href="pagination.php?page=&lt;?php echo $page-1;?&gt;" &gt;Previous&lt;/a&gt;
      &lt;?php } ?&gt;
          &lt;a href="pagination.php?page=&lt;?php if($page &lt; ceil($rowsCount/$perPage)){ echo $page+1;} else {echo 1;}?&gt;" &gt;Next&lt;/a&gt;
      &lt;/p&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>