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 . '