summaryrefslogtreecommitdiff
path: root/lib/config.php
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2022-07-09 19:40:17 +0300
committerEvgeny Zinoviev <me@ch1p.io>2022-07-09 19:40:17 +0300
commitf7bfdf58def6aadc922e1632f407d1418269a0d7 (patch)
treed7a0b2819e6a26c11d40ee0b27267ea827fbb345 /lib/config.php
initial
Diffstat (limited to 'lib/config.php')
-rw-r--r--lib/config.php46
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/config.php b/lib/config.php
new file mode 100644
index 0000000..bb7e5ca
--- /dev/null
+++ b/lib/config.php
@@ -0,0 +1,46 @@
+<?php
+
+class config {
+
+ public static function get(string $key) {
+ $db = getDb();
+ $q = $db->query("SELECT value FROM config WHERE name=?", $key);
+ if (!$db->numRows($q))
+ return null;
+ return $db->result($q);
+ }
+
+ public static function mget($keys) {
+ $map = [];
+ foreach ($keys as $key) {
+ $map[$key] = null;
+ }
+
+ $db = getDb();
+ $keys = array_map(fn($s) => $db->escape($s), $keys);
+
+ $q = $db->query("SELECT * FROM config WHERE name IN('".implode("','", $keys)."')");
+ while ($row = $db->fetch($q))
+ $map[$row['name']] = $row['value'];
+
+ return $map;
+ }
+
+ public static function set($key, $value) {
+ $db = getDb();
+ return $db->query("REPLACE INTO config (name, value) VALUES (?, ?)", $key, $value);
+ }
+
+ public static function mset($map) {
+ $rows = [];
+ foreach ($map as $name => $value) {
+ $rows[] = [
+ 'name' => $name,
+ 'value' => $value
+ ];
+ }
+ $db = getDb();
+ return $db->multipleReplace('config', $rows);
+ }
+
+}