From 1fb8c953e758ac96a61b37a576d73c46651d00d5 Mon Sep 17 00:00:00 2001 From: Max Pozdeev Date: Sun, 2 Jan 2022 19:58:12 +0300 Subject: [PATCH] use information_schema to test if mysql table exists --- src/includes/class.db.mysql.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/includes/class.db.mysql.php b/src/includes/class.db.mysql.php index 4ccc647..8b54c16 100644 --- a/src/includes/class.db.mysql.php +++ b/src/includes/class.db.mysql.php @@ -60,6 +60,7 @@ class DatabaseResult_Mysql class Database_Mysql { var $dbh; + var $dbname; var $error_str; function __construct() @@ -72,6 +73,7 @@ class Database_Mysql { throw new Exception(mysqli_connect_error()); } + $this->dbname = $db; if( @!mysqli_select_db($this->dbh, $db) ) { throw new Exception($this->error()); @@ -163,10 +165,10 @@ class Database_Mysql function table_exists($table) { - $table = addslashes($table); - $q = mysqli_query($this->dbh, "SELECT 1 FROM `$table` WHERE 1=0"); - if($q === false) return false; - else return true; + $r = $this->sq("SELECT 1 FROM information_schema.tables WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ?", + array($this->dbname, $table) ); + if ($r === false || $r === null) return false; + return true; } }