<?php
//In this example, we fetch data as an associative array.
$dsn = "mysql:host=localhost;dbname=mydb";
$user = "user12";
$passwd = "12user";
$pdo = new PDO($dsn, $user, $passwd);
$stm = $pdo->query("SELECT * FROM countries");
//In the fetchAll method, we use the PDO::FETCH_ASSOC style.
$rows = $stm->fetchAll(PDO::FETCH_ASSOC);
foreach($rows as $row) {
printf("{$row['id']} {$row['name']} {$row['population']}\n");
}
?>