Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7753411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:03:29+00:00 2026-06-01T12:03:29+00:00

Good day, I’ve been trying to figure out a problem in my code. I’m

  • 0

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.

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.

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.

So here’s my 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->db->DBH()->prepare("SELECT    SQL_CALC_FOUND_ROWS
                                                berichten.berichtID, 
                                                berichten.bericht, 
                                                berichten.naam, 
                                                berichten.mail
                                        FROM    `berichten` 
                                        ORDER BY berichten.datumToegevoegd DESC 
                                        LIMIT   ?, ?");
    $sth->bindParam(1, $offset, PDO::PARAM_INT);
    $sth->bindParam(2, $args['itemsPerPagina'], PDO::PARAM_INT);
    $sth->execute();
    $sth->setFetchMode(PDO::FETCH_ASSOC);

    $berichten = array();

    while($row = $sth->fetch())
    {
        $bericht = new Bericht();
        $bericht->setBerichtID(htmlentities(strip_tags($row['berichtID'])));
        $bericht->setBericht(htmlentities(strip_tags($row['bericht'])));
        $bericht->setNaam(htmlentities(strip_tags($row['naam'])));
        $bericht->setMail(htmlentities(strip_tags($row['mail'])));  
        $berichten[] = $bericht; 
    }

    $sth = $this->db->DBH()->prepare("SELECT FOUND_ROWS() as aantalBerichten");
    $sth->execute();
    $sth->setFetchMode(PDO::FETCH_ASSOC);
    $this->aantalBerichten = $sth->fetch();

    var_dump($this->aantalBerichten);

    return $berichten;
}

index.php

if($huidigePagina < 1)
{
    //$huidigePagina is 1
    $huidigePagina = 1;
}

//Als de huidige pagina groter is als het totaal aantal pagina's
if($huidigePagina > $totaalPaginas)
{
    //$huidigePagina is gelijk aan het totaal aantal pagina's
    $huidigePagina = $totaalPaginas;
}

$berichtDAO->findBerichten(array('huidigePagina'=>$huidigePagina, 'itemsPerPagina'=>10))

output var_dump: array(1) { ["aantalBerichten"]=> string(1) "0" }

If you’ve got any idea’s let me know because I’m willing to try just about anything right now 🙂
Here’s to hoping this question isn’t too noob! As I said, I think I’m missing something very easy here.

edit
the execute() function is correct etc. when used in if() statement it still proceeds to execute code

Also; im 90% sure this has got to do with the FOUND_ROWS() portion of code.

edit 2, included db class and Bericht() class
Bericht class:

<?php 

Class Bericht
{
    private $db;
    private $berichtID;
    private $bericht;
    private $naam;
    private $mail;

    public function __construct(Db $db)
    {
        $this->db = $db;
    }

    public function setBerichtID($berichtID)
    {
        $this->berichtID = $berichtID;
    }

    public function getBerichtID()
    {
        return $this->berichtID;
    }

    public function setBericht($bericht)
    {
        $this->bericht = $bericht;
    }

    public function getBericht()
    {
        return $this->bericht;
    }

    public function setNaam($naam)
    {
        $this->naam = $naam;
    }

    public function getNaam()
    {
        return $this->naam;
    }

    public function setMail($mail)
    {
        $this->mail = $mail;
    }

    public function getMail()
    {
        return $this->mail;
    }
}

db class:

<?php
class Db
{
    //bij het laden van Db
    public function __construct()
    {
        //voer functie connect() uit
        $this->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->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            return $DBH;
        }

        catch (PDOException $except)
        {
            echo $except->getMessage();
        }
    }

    //function to retrieve records -- not important
    public function getRecords($sth)
    {
        $rows = array();

        if($sth->execute() == true)
        {       
            $sth->setFetchMode(PDO::FETCH_OBJ);

            while($row = $sth->fetch())
            {
                $rows[] = $row;
            }

            return $rows;
        }

        else
        {
            return false;
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:03:31+00:00Added an answer on June 1, 2026 at 12:03 pm

    Not completely sure what is happening inside your DB class, so a few assumptions on this answer.

    I assume this was working at one stage on your machine similar code, so trace_mode isnt the answer.

    I assume

    $this->db->DBH() 
    

    is a function which is going off to get a new database handler for use in the database query.

    The second time you call the prepare function for DBH it is creating a new database handler which is not storing the information from the other DBH call earlier.

    A fix would be to do something like

    $dbh = $this->db->DBH(); 
    

    early in the function, then replace the prepare calls with with

    $dbh->prepare("(SQL)");
    

    Edit: Looks like at least my DB->DBH() assumption was correct!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good day! I am using Facebook graph API to retrieve Facebook users Profile feed
Good day everyone. This problem was part of another one which it as been
Good day. I am trying to fetch an asp.net label control's text value using
Good day, I'm having a problem with asp.net 2.0 viewstate. Basically, I want to
Good Day All we are trying to do is inside a trigger make sure
Good day everyone, I am building a page in ASP.NET, and using Master Pages
Good day, I am using CacheFilter to filter a certain path to my server
Good day, I am having an issue trying to get the Text on a
Good day everyone. I have a question about making and using derived classes of
Good day! I am using Xcode 3.1.4 and iPhone SDK 2.2.1. I am creating

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.