From 9c15c2fa6848d966457972fce0d04347ecbd4f2c Mon Sep 17 00:00:00 2001 From: slawkens <slawkens@gmail.com> Date: Tue, 22 Apr 2025 14:03:25 +0200 Subject: [PATCH] Add $db->hasTableAndColumns($table, $columns), credits to @opentibiabr Team --- system/libs/pot/OTS_DB_MySQL.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/system/libs/pot/OTS_DB_MySQL.php b/system/libs/pot/OTS_DB_MySQL.php index 7f424a1a..c8e73f56 100644 --- a/system/libs/pot/OTS_DB_MySQL.php +++ b/system/libs/pot/OTS_DB_MySQL.php @@ -220,6 +220,19 @@ class OTS_DB_MySQL extends OTS_Base_DB return $this->hasTable($table) && ($this->has_column_cache[$table . '.' . $column] = count($this->query('SHOW COLUMNS FROM `' . $table . "` LIKE '" . $column . "'")->fetchAll()) > 0); } + public function hasTableAndColumns(string $table, array $columns = []): bool + { + if (!$this->hasTable($table)) return false; + + foreach ($columns as $column) { + if (!$this->hasColumn($table, $column)) { + return false; + } + } + + return true; + } + public function revalidateCache() { foreach($this->has_table_cache as $key => $value) { $this->hasTableInternal($key);