php7-mysql-data/Kapitel_6/Lektion_6/pdo_loesung/mediathek.php

40 lines
735 B
PHP
Raw Permalink Normal View History

2016-08-16 21:20:53 +02:00
<?php
$pdo = new PDO(
'mysql:dbname=mediathek;host=localhost',
'root',
'root',
[
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"
]
);
$statement = $pdo->query("SELECT * FROM cds ORDER BY name ASC");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Mediathek</title>
</head>
<body>
<h1>CDs</h1>
<table>
<tr>
<th>Name</th>
<th>Erscheinungsjahr</th>
</tr>
<?php while ($datensatz = $statement->fetch(PDO::FETCH_ASSOC)) : ?>
<tr>
<td><?= htmlspecialchars($datensatz['name']); ?></td>
<td><?= htmlspecialchars($datensatz['erscheinungsjahr']); ?></td>
</tr>
<?php endwhile; ?>
</table>
</body>
</html>