Getting rowcount using PDO with a LIMIT query in MySQL

I’ve been searching here and elsewhere and have tried a few things without success. How do I get a full rowcount when doing a LIMIT query. The rowCount method only returns the rows returned by the LIMIT. If I use SQL_CALC_FOUND_ROWS I can’t quite figure out how and when to run SELECT FOUND_ROWS() within the PDO framework. Any help would be appreciated. Thanks

Success! This works fine. Is this the best way to do it or is there a more efficient way to do this?

$sth = $this->dbh->prepare($qt_sql);
        $sth->bindParam(':companyid', $_SESSION['user']['companyid'], PDO::PARAM_INT);
        $sth->execute();

        $info = $sth->fetchAll(PDO::FETCH_ASSOC);
        $sth = $this->dbh->prepare("SELECT FOUND_ROWS() as rowcount");
        $sth->execute();
        $cnt = $sth->fetchAll(PDO::FETCH_ASSOC);

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.