X-Git-Url: http://git.shiar.net/minimedit.git/blobdiff_plain/75cbd3cb3b7e08963686ca81976c086fd531a8b8..3e188c002a26457a93ec3844bc6c7db3b0b23b10:/database.inc.php diff --git a/database.inc.php b/database.inc.php index aa864d0..2183358 100644 --- a/database.inc.php +++ b/database.inc.php @@ -8,7 +8,10 @@ class DB function __construct($config, $options = []) { - $options += [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ]; + $options += [ + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ, + ]; $this->dbh = new PDO($config, NULL, NULL, $options); } @@ -18,4 +21,14 @@ class DB $stmt->execute($params); return $stmt; } + + function insert($table, $row) + { + $sql = sprintf('INSERT INTO %s (%s) VALUES (%s)', + '"'.$table.'"', + implode(', ', array_keys($row)), + implode(', ', array_fill(0, count($row), '?')) + ); + return $this->query($sql, array_values($row)); + } }