Created
March 3, 2024 19:41
-
-
Save muathendirangu/d57ef7b086af1747e115eea64d5ca505 to your computer and use it in GitHub Desktop.
The following code shows how to query all rows from the authors table using PDO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$pdo = require 'connect.php'; | |
$sql = 'SELECT author_id, name | |
FROM authors'; | |
$statement = $pdo->query($sql); | |
// get all authors | |
$authors = $statement->fetchAll(PDO::FETCH_ASSOC); | |
if ($authors) { | |
// show the authors | |
foreach ($authors as $author) { | |
echo $author['name'] . '<br>'; | |
} | |
} | |
// Output sample | |
Ngugi Wa Thiongo | |
Caleb Amisi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment