]> git.bts.cx Git - cx.git/blob - cx/lib/db.php
Try to fix aspect ratio issues
[cx.git] / cx / lib / db.php
1 <?php
2
3 function _cx_db() {
4 static $db = new SQLite3(CX_DATABASE_FILE);
5 return $db;
6 }
7
8 function _cx_db_sql_exec($sql, ...$args) {
9 $db = _cx_db();
10 $statement = $db->prepare($sql);
11
12 foreach ($args as $i => $arg) {
13 $idx = $i + 1;
14 $statement->bindValue($idx, $arg);
15 }
16
17 return $statement->execute();
18 }
19
20 function cx_db_exec($sql, ...$args) {
21 _cx_db_sql_exec($sql, ...$args);
22 return _cx_db()->lastInsertRowID();
23 }
24
25 function cx_db_query($sql, ...$args) {
26 $result_set = _cx_db_sql_exec($sql, ...$args);
27 while ($result = $result_set->fetchArray()) {
28 yield $result;
29 }
30 }