From 7effc2c6d668e2716822684c2a7b537cc53be668 Mon Sep 17 00:00:00 2001 From: WispX <1591788658@qq.com> Date: Sat, 14 Mar 2020 19:42:06 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E5=8E=BB=E9=99=A4=E6=97=A7?= =?UTF-8?q?=E7=89=88=E6=9B=B4=E6=96=B0=E6=95=B0=E6=8D=AE=E5=BA=93=E7=BB=93?= =?UTF-8?q?=E6=9E=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/index/controller/Install.php | 104 ------------------ application/index/controller/admin/System.php | 1 + 2 files changed, 1 insertion(+), 104 deletions(-) diff --git a/application/index/controller/Install.php b/application/index/controller/Install.php index c3d6970b..78a8492e 100644 --- a/application/index/controller/Install.php +++ b/application/index/controller/Install.php @@ -166,108 +166,4 @@ EOT; ]); return $this->fetch(); } - - public function update($start = 0) - { - try { - $user = false; - if (Session::has('uid')) { - $user = Users::get(Session::get('uid')); - if (!$user) { - Session::delete('uid'); - } - } - - if (!$user || !$user->is_admin) { - $this->redirect(url('/')); - } - - $path = Env::get('root_path') . 'update.sql'; - $file = @file_get_contents($path); - if (!$file) { - $this->redirect(url('/')); - } - - $code = 0; - $msg = null; - if ($start == 1) { - if ($file) { - $config = Config::pull('db'); - - // 替换sql关键字 - $file = str_replace([ - '{database}' - ], [ - $config['database'] - ], $file); - - $mysqli = new \mysqli( - $config['hostname'], - $config['username'], - $config['password'], - $config['database'], - $config['hostport'] - ); - if ($mysqli->connect_errno) { - $mysqli->close(); - throw new Exception($mysqli->connect_error); - } - - $mysqli->autocommit(false); - $mysqli->select_db($config['database']); - $mysqli->query("SET NAMES utf8"); - - // 新建表字段 - $tableFields = Config::pull('table'); - - foreach ($tableFields as $table => $fields) { - foreach ($fields as $field => $sql) { - $fetchFields = $mysqli->query("DESCRIBE `{$table}`;"); - // 判断字段是否已存在 - $flag = true; - foreach ($fetchFields as $fetchField) { - if ($field == $fetchField['Field']) { - $flag = false; - } - } - if ($flag) { - if (!$mysqli->query($sql)) { - throw new Exception($mysqli->error); - } - } - } - } - - foreach (explode(';', $file) as $value) { - if ($value && !ctype_space($value)) { - if (!$mysqli->query($value . ';')) { - throw new Exception('
数据导入失败!
错误信息:
' . $mysqli->error . '
sql语句:
' . $value . '