title: PDO PHP & MYSQL SELECT FOUND_ROWS() always returns 0
body: <p>Good day, I've been trying to figure out a problem in my code. I'm using SQL_CALC_FOUND_ROWS and FOUND_ROWS() to retrieve the total amount of records in my database (with PDO). My problem is that FOUND_ROWS() always returns 0.</p>
  
  <p>The thing is that I got it working before, but I made some adjustments here and there and now it stopped working. I can't for the love of me remember what I could have deleted that was important and can't seem to find any good documentation using these functions with PDO.</p>
  
  <p>So far I've tried putting it in different loops, tried fetch() with different modes, tried placing the commands in different order (i.e. before the while and after the while loop etc.). I think I'm just missing something very easy here, but I've been staring it this thing for about 1 or 2 hours now and it's driving me mad.</p>
  
  <p>So here's my code:</p>
  
  <pre><code>public function findBerichten($args)
  {       
      //$offset zorg ervoor dat pagina 1 als record 0 in de database zoekt
      $offset = ($args['huidigePagina'] - 1) * $args['itemsPerPagina'];
  
      $sth = $this-&gt;db-&gt;DBH()-&gt;prepare("SELECT    SQL_CALC_FOUND_ROWS
                                                  berichten.berichtID, 
                                                  berichten.bericht, 
                                                  berichten.naam, 
                                                  berichten.mail
                                          FROM    `berichten` 
                                          ORDER BY berichten.datumToegevoegd DESC 
                                          LIMIT   ?, ?");
      $sth-&gt;bindParam(1, $offset, PDO::PARAM_INT);
      $sth-&gt;bindParam(2, $args['itemsPerPagina'], PDO::PARAM_INT);
      $sth-&gt;execute();
      $sth-&gt;setFetchMode(PDO::FETCH_ASSOC);
  
      $berichten = array();
  
      while($row = $sth-&gt;fetch())
      {
          $bericht = new Bericht();
          $bericht-&gt;setBerichtID(htmlentities(strip_tags($row['berichtID'])));
          $bericht-&gt;setBericht(htmlentities(strip_tags($row['bericht'])));
          $bericht-&gt;setNaam(htmlentities(strip_tags($row['naam'])));
          $bericht-&gt;setMail(htmlentities(strip_tags($row['mail'])));  
          $berichten[] = $bericht; 
      }
  
      $sth = $this-&gt;db-&gt;DBH()-&gt;prepare("SELECT FOUND_ROWS() as aantalBerichten");
      $sth-&gt;execute();
      $sth-&gt;setFetchMode(PDO::FETCH_ASSOC);
      $this-&gt;aantalBerichten = $sth-&gt;fetch();
  
      var_dump($this-&gt;aantalBerichten);
  
      return $berichten;
  }
  </code></pre>
  
  <p>index.php</p>
  
  <pre><code>if($huidigePagina &lt; 1)
  {
      //$huidigePagina is 1
      $huidigePagina = 1;
  }
  
  //Als de huidige pagina groter is als het totaal aantal pagina's
  if($huidigePagina &gt; $totaalPaginas)
  {
      //$huidigePagina is gelijk aan het totaal aantal pagina's
      $huidigePagina = $totaalPaginas;
  }
  
  $berichtDAO-&gt;findBerichten(array('huidigePagina'=&gt;$huidigePagina, 'itemsPerPagina'=&gt;10))
  </code></pre>
  
  <p>output var_dump: <code>array(1) { ["aantalBerichten"]=&gt; string(1) "0" }</code> </p>
  
  <p>If you've got any idea's let me know because I'm willing to try just about anything right now :)<br>
  Here's to hoping this question isn't too noob! As I said, I think I'm missing something very easy here.</p>
  
  <p><strong>edit</strong><br>
  the execute() function is correct etc. when used in if() statement it still proceeds to execute code</p>
  
  <p>Also; im 90% sure this has got to do with the FOUND_ROWS() portion of code.</p>
  
  <p><strong>edit 2, included db class and Bericht() class</strong><br>
  Bericht class:</p>
  
  <pre><code>&lt;?php 
  
  Class Bericht
  {
      private $db;
      private $berichtID;
      private $bericht;
      private $naam;
      private $mail;
  
      public function __construct(Db $db)
      {
          $this-&gt;db = $db;
      }
  
      public function setBerichtID($berichtID)
      {
          $this-&gt;berichtID = $berichtID;
      }
  
      public function getBerichtID()
      {
          return $this-&gt;berichtID;
      }
  
      public function setBericht($bericht)
      {
          $this-&gt;bericht = $bericht;
      }
  
      public function getBericht()
      {
          return $this-&gt;bericht;
      }
  
      public function setNaam($naam)
      {
          $this-&gt;naam = $naam;
      }
  
      public function getNaam()
      {
          return $this-&gt;naam;
      }
  
      public function setMail($mail)
      {
          $this-&gt;mail = $mail;
      }
  
      public function getMail()
      {
          return $this-&gt;mail;
      }
  }
  </code></pre>
  
  <p>db class:</p>
  
  <pre><code>&lt;?php
  class Db
  {
      //bij het laden van Db
      public function __construct()
      {
          //voer functie connect() uit
          $this-&gt;connect();
      }
  
      //functie voor het verbinding maken met en het selecteren van een database
      private function connect()
      {
          //$connection is connectie naar mysql database (met de opgegeven inlog waardes)
          $connection = mysql_connect('localhost', 'user', 'pw');
  
          //als er geen connectie gemaakt kan worden
          if(!$connection)
          {
              //die (voer overige code niet meer uit) en echo string + de mysql error
              die("Kan geen verbinding maken: " . mysql_error());
          }
  
          //selecteert de opgegeven database met de connectie ($connection)
          mysql_select_db("db", $connection);
      }
  
      public function DBH()
      {
          try 
          {
              $DBH = new PDO('mysql:host=localhost;dbname=db', 'user', 'pw');
              $DBH-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
              return $DBH;
          }
  
          catch (PDOException $except)
          {
              echo $except-&gt;getMessage();
          }
      }
  
      //function to retrieve records -- not important
      public function getRecords($sth)
      {
          $rows = array();
  
          if($sth-&gt;execute() == true)
          {       
              $sth-&gt;setFetchMode(PDO::FETCH_OBJ);
  
              while($row = $sth-&gt;fetch())
              {
                  $rows[] = $row;
              }
  
              return $rows;
          }
  
          else
          {
              return false;
          }
      }
  }
  </code></pre>