How can you count and output data records in PHP using PDO?

To count and output data records in PHP using PDO, you can execute a SQL query to count the number of records and then fetch and display the result. You can achieve this by using the `rowCount()` method to count the number of records returned by the query and then fetching the data using `fetch()` or `fetchAll()` method to display the records.

// Connect to the database using PDO
$pdo = new PDO('mysql:host=localhost;dbname=database_name', 'username', 'password');

// Prepare and execute the SQL query to count records
$stmt = $pdo->query("SELECT COUNT(*) FROM table_name");
$count = $stmt->fetchColumn();

// Output the count of records
echo "Total records: " . $count;