Well, I woundn't do as suggested querying twice the database to get the count and then get the data I want. It would be simpler and would give better performance to query once and retrieve both, record count and the data itself
<?php
$sql = "SELECT * FROM fruit WHERE calories > :calories";
$sth = $conn->prepare($sql);
$sth->bindParam(':calories', 100, PDO::PARAM_INT);
$res = $sth->execute();
if ($res) {
$record = $sth->fetchAll();
if (count($record) > 0) {
foreach ($record as $row) {
print "Name: " . $row['NAME'] . "\n";
}
}
else {
print "No rows matched the query.";
}
}
$conn = null;
?>