What is the best practice for counting the results of a database query in PHP?

When counting the results of a database query in PHP, the best practice is to use the `rowCount()` method provided by the PDO (PHP Data Objects) extension. This method returns the number of rows affected by the last SQL statement. It is more efficient and reliable than manually counting the rows in the result set.

// Assuming $pdo is your PDO object and $query is your SQL query

$stmt = $pdo->query($query);
$rowCount = $stmt->rowCount();

echo "Number of rows: " . $rowCount;