From 2f2fa9f27db1dc630180babf7efa206157f37003 Mon Sep 17 00:00:00 2001 From: Laria Carolin Chabowski Date: Sun, 8 Nov 2020 17:03:39 +0100 Subject: Make dbversion a method of Database We currently don't actually use it, but it might come in handy, so let's keep it. --- ratatoeskr/sys/Database.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'ratatoeskr/sys/Database.php') diff --git a/ratatoeskr/sys/Database.php b/ratatoeskr/sys/Database.php index 4f9014a..d9fc327 100644 --- a/ratatoeskr/sys/Database.php +++ b/ratatoeskr/sys/Database.php @@ -110,4 +110,24 @@ class Database { return (int)$this->pdo->lastInsertId(); } + + /** + * Get the version of the database structure currently used. + * @return int + */ + public function dbversion(): int + { + $tableName = $this->subPrefix("PREFIX_meta"); + + /* Is the meta table present? If no, the version is 0. */ + $stmt = $this->query("SHOW TABLES LIKE ?", $tableName); + list($table) = $stmt->fetch(); + if ($table != $tableName) { + return 0; + } + + $stmt = $this->query("SELECT `value` FROM `PREFIX_meta` WHERE `key` = 'dbversion'"); + $sqlrow = $stmt->fetch(); + return (int)unserialize(base64_decode($sqlrow["value"])); + } } -- cgit v1.2.3-70-g09d2