<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

$host = "192.168.1.20";
$database = "ospedale";
$user = "pdo";
$password = "";

$datiPazienti = [];

try {
    $connection = new PDO("mysql:host=$host;dbname=$database", $user, $password);
    echo "Connected successfully<br>";

    $prepare = $connection->prepare("SELECT cognome, nome, note FROM pazienti");
    $prepare->execute();
    if ($prepare->rowCount() > 0) {
        $datiPazienti = $prepare->fetchAll();
    }
    $connection = null;

} catch (PDOException $e) {
    die ("Error!: " . $e->getMessage() . "<br/>");
}
?>

<html lang="en">

<head>
    <title>HTML</title>
    <link
            rel="stylesheet"
            href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css"
    >
</head>

<body>
    <table>
        <tr>
            <th>Cognome</th>
            <th>Nome</th>
            <th>Note</th>
        </tr>
        <?php foreach ($datiPazienti as $row) {
            echo '<tr>';
            echo '<td>' . htmlspecialchars($row['cognome']) . '</td>';
            echo '<td>' . htmlspecialchars($row['nome']) . '</td>';
            echo '<td>' . htmlspecialchars($row['note']) . '</td>';
            echo '</tr>';
        }
        ?>
    </table>
</body>

</html>
