about summary refs log tree commit diff stats
path: root/classes/Db.php
diff options
context:
space:
mode:
authorAndrew Dolgov <fox@fakecake.org>2026-05-31 09:11:20 +0300
committerAndrew Dolgov <fox@fakecake.org>2026-05-31 09:11:20 +0300
commitb58f0a8f2431040edf94edb21f9c884f20ba6049 (patch)
treeb70055bf14983a59242ae27cdba75f6d39d391a3 /classes/Db.php
parentb76af33e9bfb57b46fb8d8292b614bf9ee2e3c2d (diff)
downloadthe-epube-b58f0a8f2431040edf94edb21f9c884f20ba6049.tar.gz
the-epube-b58f0a8f2431040edf94edb21f9c884f20ba6049.tar.xz
tabs to spaces
Diffstat (limited to 'classes/Db.php')
-rw-r--r--classes/Db.php120
1 files changed, 60 insertions, 60 deletions
diff --git a/classes/Db.php b/classes/Db.php
index dcaa482..7f5a9f4 100644
--- a/classes/Db.php
+++ b/classes/Db.php
@@ -1,65 +1,65 @@
 <?php
 
 class Db {
-	private static ?Db $instance = null;
-
-	private PDO $pdo;
-
-	private function __construct() {
-		$db_type = Config::get(Config::DB_TYPE);
-
-		try {
-			$this->pdo = new PDO(self::get_dsn(),
-				Config::get(Config::DB_USER),
-				Config::get(Config::DB_PASS));
-
-			if ($db_type == 'sqlite') {
-				$this->pdo->query('PRAGMA journal_mode = wal');
-			}
-		} catch (Exception $e) {
-			user_error($e, E_USER_WARNING);
-			die("Unable to initialize database driver: " . Config::get(Config::DB_TYPE));
-		}
-
-		$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
-
-		try {
-			ORM::configure(self::get_dsn());
-			ORM::configure('return_result_sets', true);
-
-			if ($db_type == 'pgsql') {
-				ORM::configure('username', Config::get(Config::DB_USER));
-				ORM::configure('password', Config::get(Config::DB_PASS));
-				ORM::configure('return_result_sets', true);
-			} else {
-				ORM::raw_execute('PRAGMA journal_mode = wal');
-			}
-
-		} catch (Exception $e) {
-			user_error($e, E_USER_WARNING);
-			die("Unable to initialize ORM layer.");
-		}
-	}
-
-	public static function get_dsn() : string {
-		$db_type = Config::get(Config::DB_TYPE);
-
-		if ($db_type == 'pgsql') {
-			$db_port = Config::get(Config::DB_PORT) ? ';port=' . Config::get(Config::DB_PORT) : '';
-			$db_host = Config::get(Config::DB_HOST) ? ';host=' . Config::get(Config::DB_HOST) : '';
-
-			return $db_type . ':dbname=' . Config::get(Config::DB_NAME) . $db_host . $db_port;
-
-		} else {
-			return $db_type . ':' . Config::get(Config::SCRATCH_DB);
-		}
-	}
-
-	public static function pdo() : PDO {
-		if (self::$instance == null)
-			self::$instance = new self();
-
-		return self::$instance->pdo;
-	}
+    private static ?Db $instance = null;
+
+    private PDO $pdo;
+
+    private function __construct() {
+        $db_type = Config::get(Config::DB_TYPE);
+
+        try {
+            $this->pdo = new PDO(self::get_dsn(),
+                Config::get(Config::DB_USER),
+                Config::get(Config::DB_PASS));
+
+            if ($db_type == 'sqlite') {
+                $this->pdo->query('PRAGMA journal_mode = wal');
+            }
+        } catch (Exception $e) {
+            user_error($e, E_USER_WARNING);
+            die("Unable to initialize database driver: " . Config::get(Config::DB_TYPE));
+        }
+
+        $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+
+        try {
+            ORM::configure(self::get_dsn());
+            ORM::configure('return_result_sets', true);
+
+            if ($db_type == 'pgsql') {
+                ORM::configure('username', Config::get(Config::DB_USER));
+                ORM::configure('password', Config::get(Config::DB_PASS));
+                ORM::configure('return_result_sets', true);
+            } else {
+                ORM::raw_execute('PRAGMA journal_mode = wal');
+            }
+
+        } catch (Exception $e) {
+            user_error($e, E_USER_WARNING);
+            die("Unable to initialize ORM layer.");
+        }
+    }
+
+    public static function get_dsn() : string {
+        $db_type = Config::get(Config::DB_TYPE);
+
+        if ($db_type == 'pgsql') {
+            $db_port = Config::get(Config::DB_PORT) ? ';port=' . Config::get(Config::DB_PORT) : '';
+            $db_host = Config::get(Config::DB_HOST) ? ';host=' . Config::get(Config::DB_HOST) : '';
+
+            return $db_type . ':dbname=' . Config::get(Config::DB_NAME) . $db_host . $db_port;
+
+        } else {
+            return $db_type . ':' . Config::get(Config::SCRATCH_DB);
+        }
+    }
+
+    public static function pdo() : PDO {
+        if (self::$instance == null)
+            self::$instance = new self();
+
+        return self::$instance->pdo;
+    }
 
 };