MySQL with PHP
Prepare, execute, fetch — safely, with prepared statements.
SELECT * FROM books WHERE available_copies > 0;
Result
| col 1 | col 2 | col 3 | col 4 |
|---|---|---|---|
| bk001 | Data Structures | Aho | 3 |
| bk002 | Database Systems | Elmasri | 2 |
| bk004 | Computer Networks | Tanenbaum | 5 |
$pdo = new PDO("mysql:host=localhost;dbname=library", $user, $pass);
$stmt = $pdo->prepare(<<<SQL
SELECT * FROM books WHERE available_copies > 0;
SQL);
$stmt->execute();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo htmlspecialchars($row['title'] ?? '');
}
Prepared statements prevent SQL injection — values are never interpolated into the query text.