I can't find a way of finding the number of rows returned, after scouring the manual and other questions. How can I modify my fetchAll() method?
class Product {
var $count;
public function fetchAll(){
$this->query = $this->pdo->prepare("SELECT * FROM $table");
$this->query->setFetchMode( PDO::FETCH_ASSOC );
$this->query->execute();
}
public function next(){
$this->row = $this->query->fetch();
if (!is_array($this->row)) return false;
foreach ($this->row as $key => $val) {
$this->{$key} = $val;
}
}
public function getCount(){
return $this->count;
}
}
$records = $stmt->fetchAll(PDO::FETCH_ASSOC); $num_rows = count($rows);voila, you're done.