There are many conflicting statements around. What is the best way to get the row count using PDO in PHP? Before using PDO, I just simply used mysql_num_rows
.>
I tried $count = $stmt->rowCount();
with Oracle 11.2 and it did not work.
I decided to used a for loop as show below.
$count = "";
$stmt = $conn->prepare($sql);
$stmt->execute();
echo "\n";
while($row = $stmt->fetch(PDO::FETCH_OBJ)) {
$count++;
echo "\n";
foreach ($row as $item) {
echo "".($item !== null ? htmlentities($item, ENT_QUOTES):" ")." \n";
} //foreach ends
}// while ends
echo "
\n";
//echo " no of rows : ". oci_num_rows($stmt);
//equivalent in pdo::prepare statement
echo "no.of rows :".$count;