The problem is rowCount (pdo method to return the count) will always return the number of items affected by the query, even if I have used fetch. So does anyone know how I can get the correct number?
Small example of what I mean
Code: Select all
try {
$pdo = new PDO("mysql:host=localhost;dbname=db","pass","username");
} catch (PDOException $e) {
echo "Failed to get DB handle: " . $e->getMessage() . "\n";
exit;
}
$sql = "SELECT * FROM teste"; //this will return 4 rows
$res = $pdo->query($sql);
while (($row = $res->fetch(PDO::FETCH_OBJ))) {
echo $res->rowCount(); // <-- This will always echo 4
echo $row->texto . "<br>";
}