1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
<head>
<title>Siphon 2.0</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<?php
// TODO: On commence par contrôler les variables (si elles sont du type correct
// et si leurs valeurs ne sont pas délirantes. Si ce n'est pas le cas, mieux
// vaut interrompre le script.
// Si c'est OK, alors on les stocke dans des variables (ce qui évite de se
// trimbaler des `$_GET` jusqu'à la fin du script).
$temp = $_GET['temp'];
$niveau = $_GET['niveau'];
?>
<h2>Valeurs</h2>
<p>Température <?= $temp ?></p>
<p>Niveau d'eau <?= $niveau ?></p>
<h2>Ajout en BDD</h2>
<?php
$host = 'localhost';
$dbname = 'test';
$user = 'root';
$pass = '***';
$port = '3307';
$charset = 'utf8mb4';
$dsn = "mysql:$host;dbname=$dbname;charset=$charset;port=$port";
$options = [
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
\PDO::ATTR_EMULATE_PREPARES => false
];
try {
$pdo = new \PDO($dsn, $user, $pass, $options);
} catch (\PDOException $e) {
throw new \PDOException($e->getMessage(), (int)$e->getCode());
}
$query = 'INSERT INTO t_siphon (sph_date, sph_temp, sph_niveau)
VALUES (:date, :temp, :niveau)';
$stmt = $pdo->prepare($query);
$stmt->execute([
'date' => date('Y-m-d'),
'temp' => $temp,
'niveau' => $niveau
]);
?>
</body>
</html> |
Partager