nieuws/replies: database class with query method
[minimedit.git] / database.inc.php
index 6e040d46d8cba08d3a9cef90d9cbba5637f0b2ac..aa864d03df32f5dadedba9441512331f5fe10d5c 100644 (file)
@@ -1,4 +1,21 @@
 <?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;
+       }
+}