From 2c00e4fa6747552630ccedb495b9a4e6c7b5b5fa Mon Sep 17 00:00:00 2001 From: printempw Date: Wed, 3 Feb 2016 00:11:43 +0800 Subject: [PATCH] add notification if db info is correct but no tables in it --- includes/database.class.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/includes/database.class.php b/includes/database.class.php index a3211c47..57f0aea5 100644 --- a/includes/database.class.php +++ b/includes/database.class.php @@ -3,7 +3,7 @@ * @Author: printempw * @Date: 2016-02-02 21:59:06 * @Last Modified by: prpr - * @Last Modified time: 2016-02-02 23:48:47 + * @Last Modified time: 2016-02-03 00:10:17 */ class database @@ -20,9 +20,20 @@ class database utils::raise(-1, "Can not connect to mysql, check if database info correct in config.php. ". $conn->connect_error); } + if (!self::checkTableExist($conn)) { + utils::raise(-1, "Looks like that there is no `users` table in your database. ". + "Please run `/admin/install.php` first."); + } return $conn; } + public static function checkTableExist($conn) { + $sql = "SELECT table_name FROM + `INFORMATION_SCHEMA`.`TABLES` WHERE table_name ='users' + AND TABLE_SCHEMA='".DB_NAME."'"; + return ($conn->query($sql)->num_rows != 0) ? true : false; + } + public function query($sql) { $result = $this->connection->query($sql); if (!$this->connection->error) {