<?php
$dsn = require '.dbconfig.inc.php';
-$options = [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ];
-$Db = new PDO($dsn, NULL, NULL, $options);
+$Db = new DB($dsn);
+
+class DB
+{
+ public $dbh;
+
+ function __construct($config, $options = [])
+ {
+ $options += [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ];
+ $this->dbh = new PDO($config, NULL, NULL, $options);
+ }
+
+ function query($sql, $params = [])
+ {
+ $stmt = $this->dbh->prepare($sql);
+ $stmt->execute($params);
+ return $stmt;
+ }
+}
try {
$html = nl2br(htmlspecialchars($_POST['reply']));
$html = "<p>$html</p>";
- $query = $Db->prepare('INSERT INTO comments (page, message, author) VALUES (?, ?, ?)');
- $query->execute([ $Page, $html, $User->login ]);
+ $query = $Db->query('INSERT INTO comments (page, message, author) VALUES (?, ?, ?)', [
+ $Page, $html, $User->login
+ ]);
if (!$query->rowCount()) {
throw new Exception('Fout bij opslaan');
}
}
}
-$query = $Db->prepare('SELECT * FROM comments WHERE page = ? ORDER BY created');
-$query->execute([$Page]);
+$query = $Db->query('SELECT * FROM comments WHERE page = ? ORDER BY created', [$Page]);
print '<ul class="replies">';