diff options
| author | winter | 2024-12-07 21:44:42 +0000 |
|---|---|---|
| committer | winter | 2024-12-07 21:44:42 +0000 |
| commit | a84232811dadccf7047424f27340a7f9847bedff (patch) | |
| tree | a6a0823c8b9485b6a5b60ea7ae854f9511a6ae1e /WpfTest/Db.php | |
| parent | e1ad307b531c27ec6bfaf8b4d018991b0d4a78f3 (diff) | |
many many changes but actors are loaded from db now
Diffstat (limited to 'WpfTest/Db.php')
| -rw-r--r-- | WpfTest/Db.php | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/WpfTest/Db.php b/WpfTest/Db.php new file mode 100644 index 0000000..3de1011 --- /dev/null +++ b/WpfTest/Db.php @@ -0,0 +1,41 @@ +<?php +namespace WpfTest; + +use WpfTest\Model\Actor; + +class Db extends Singleton { + private const INIT_SCHEMA_PATH = __DIR__ . '/../schema.sql'; + + private \PDO $conn; + + protected function __construct() { + $this->conn = new \PDO('pgsql:host=localhost;dbname=wpftest', 'wpftest', 'wpftest', [ + \PDO::ATTR_PERSISTENT => true, + ]); + } + + public function runInitialSchema() { + $this->conn->exec(file_get_contents(self::INIT_SCHEMA_PATH)); + } + + public function getDbVersion(): int { + $result = $this->conn->query('SELECT db_version FROM db_version'); + return $result->fetch()['db_version']; + } + + /** + * Changes the database schema version + * + * CAREFUL! this shouldn't be used unless you absolutely know why + * @param int $newVersion the new version number + * @return void + */ + public function setDbVersion(int $newVersion) { + $stmt = $this->conn->prepare('UPDATE db_version SET db_version = ?'); + $stmt->execute([$newVersion]); + } + + public function getPdo(): \PDO { + return $this->conn; + } +}
\ No newline at end of file |
