How can one ensure portability when using rowCount() with PDO Prepared Statements in PHP, considering different database drivers?

When using rowCount() with PDO Prepared Statements in PHP, it's important to consider that different database drivers may not always return the row count as expected. To ensure portability, it's recommended to fetch all rows from the result set and then count the number of rows manually. This approach guarantees consistent behavior across different database drivers.

$stmt = $pdo->prepare("SELECT * FROM table_name WHERE column = :value");
$stmt->execute(['value' => $someValue]);

$rows = $stmt->fetchAll();
$rowCount = count($rows);

echo "Number of rows: " . $rowCount;