What is the recommended method to retrieve the number of rows returned by a SELECT query using PDOStatement in PHP?

When using PDOStatement in PHP to execute a SELECT query, the number of rows returned can be retrieved using the `rowCount()` method. This method returns the number of rows affected by the last SQL statement, which in the case of a SELECT query, represents the number of rows returned by the query. It is important to note that `rowCount()` may not work with all database drivers, so it is recommended to use a different approach if needed.

// Execute a SELECT query
$stmt = $pdo->query("SELECT * FROM table_name");

// Retrieve the number of rows returned
$rowCount = $stmt->rowCount();

// Display the number of rows
echo "Number of rows returned: " . $rowCount;