blob: 61467eba0e5c5685174ba1dc517dfcd6dd4aedce (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
<?php
class Db {
private static $instance;
private $pdo;
private function __construct() {
try {
$this->pdo = new PDO(self::get_dsn());
} catch (Exception $e) {
user_error($e, E_USER_WARNING);
die("Unable to initialize database driver (SQLite).");
}
//$this->dbh->busyTimeout(30*1000);
$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->pdo->query('PRAGMA journal_mode = wal');
try {
ORM::configure(self::get_dsn());
ORM::configure('return_result_sets', true);
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() {
return Config::get(Config::DB_TYPE) . ':' . Config::get(Config::SCRATCH_DB);
}
public static function pdo() : PDO {
if (self::$instance == null)
self::$instance = new self();
return self::$instance->pdo;
}
};
?>
|