<?php
//In this code example, we get data in an indexed array.
$dsn = "mysql:host=localhost;dbname=mydb";
$user = "user12";
$passwd = "12user";
$pdo = new PDO($dsn, $user, $passwd);
//We select all data from the countries table.
$stm = $pdo->query("SELECT * FROM countries");
//We pass the PDO:FETCH_NUM style to the fetchAll method.
$rows = $stm->fetchAll(PDO::FETCH_NUM);
//We go over the $rows array and print the fields. The fields are accessed via array indexes.
foreach($rows as $row) {
printf("$row[0] $row[1] $row[2]\n");
}
?>
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter