code: public function count()
      {
          $sql = $this->getCountSql();
          $results = $this->query("SELECT COUNT(*) AS count FROM (".$sql.") AS result");
  
          return (int) $results[0]->count;
      }
docs: Get count