function runquery($sql) { global $tablepre, $db; if (!isset($sql) || empty($sql)) { return; } $sql = str_replace("\r", "\n", str_replace('33hao_', $tablepre, $sql)); $ret = array(); $num = 0; foreach (explode(";\n", trim($sql)) as $query) { $ret[$num] = ''; $queries = explode("\n", trim($query)); foreach ($queries as $query) { $ret[$num] .= isset($query[0]) && $query[0] == '#' || isset($query[1]) && isset($query[1]) && $query[0] . $query[1] == '--' ? '' : $query; } $num++; } unset($sql); foreach ($ret as $key => $query) { $query = trim($query); if ($query) { if (substr($query, 0, 12) == 'CREATE TABLE') { $line = explode('`', $query); $data_name = $line[1]; showjsmessage('数据表' . ' ' . $data_name . ' ... ' . '建立成功', $key); $db->query($query); } elseif (substr($query, 0, 11) == 'ALTER TABLE') { $db->query($query); } else { $db->query($query); } } } }
function add_site_config() { global $tablepre, $db; $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`) VALUES (NULL, '1', 'statis_code', 'textarea', '', '', '', '23')"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`) VALUES (NULL, '1', 'max_left_days', 'text', '', '', '2', '32')"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`) VALUES (NULL, '0', 'open_platform', 'group', '', '', '', '24')"; $db->query($sql); $parent_id = $db->insert_id(); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`) VALUES (NULL, {$parent_id}, 'qq_appid', 'text', '', '', '', '25')"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`) VALUES (NULL, {$parent_id}, 'qq_appkey', 'text', '', '', '', '26')"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`) VALUES (NULL, {$parent_id}, 'qq_open', 'select', '0,1', '', '1', '27')"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`) VALUES (NULL, {$parent_id}, 'sina_wb_akey', 'text', '', '', '', '28')"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`) VALUES (NULL, {$parent_id}, 'sina_wb_skey', 'text', '', '', '', '29')"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`) VALUES (NULL, {$parent_id}, 'sina_wb_office_id', 'text', '', '', '', '30')"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`) VALUES (NULL, {$parent_id}, 'sina_wb_open', 'select', '0,1', '', '1', '31')"; $db->query($sql); showjsmessage('增加新的系统设置项 ... 完成'); }
function runquery($sql, $showmessage = TRUE) { global $db; $dbcharset = "utf8"; $sql = str_replace("\r", "\n", $sql); $ret = array(); $num = 0; foreach (explode(";\n", trim($sql)) as $query) { $queries = explode("\n", trim($query)); foreach ($queries as $query) { @($ret[$num] .= $query[0] == '#' || $query[0] . $query[1] == '--' ? '' : $query); } $num++; } unset($sql); foreach ($ret as $query) { $query = trim($query); if ($query) { if (substr($query, 0, 12) == 'CREATE TABLE') { $name = preg_replace("/CREATE TABLE IF NOT EXISTS ([a-z0-9_]+) .*/is", "\\1", $query); $showmessage && showjsmessage('建立数据表 ' . $name . ' ... 成功!'); $db->query(createtable($query, $dbcharset)); } else { $db->query($query); } } } }
function add_site_config() { global $tablepre, $db; $sql = "SELECT id FROM " . $tablepre . "site_config WHERE code='hidden' LIMIT 1"; $group_hidden_id = $db->fetch_array($db->query($sql)); if (!$group_hidden_id) { $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, 0, 'hidden', 'hidden', '', '', '', 1)"; $db->query($sql); $group_hidden_id = $db->insert_id(); } else { $group_hidden_id = $group_hidden_id['id']; } if (!$db->fetch_array($db->query("SELECT id FROM " . $tablepre . "site_config WHERE code='captcha' LIMIT 1"))) { $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_hidden_id}', 'captcha', 'hidden', '', '', '', 1)"; $db->query($sql); } if (!$db->fetch_array($db->query("SELECT id FROM " . $tablepre . "site_config WHERE code='captcha_width' LIMIT 1"))) { $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_hidden_id}', 'captcha_width', 'hidden', '', '', '', 1)"; $db->query($sql); } if (!$db->fetch_array($db->query("SELECT id FROM " . $tablepre . "site_config WHERE code='captcha_height' LIMIT 1"))) { $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_hidden_id}', 'captcha_height', 'hidden', '', '', '', 1)"; $db->query($sql); } showjsmessage('增加新的系统设置项 ... 完成'); }
function edit_table_user() { global $tablepre, $db; $sql = "ALTER TABLE `" . $tablepre . "user` ADD `invite` MEDIUMINT( 8 ) UNSIGNED NOT NULL DEFAULT '0',ADD INDEX ( `invite` )"; $db->query($sql); $sql = "ALTER TABLE `" . $tablepre . "user` ADD `addtime` INT( 11 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `credit`"; $db->query($sql); showjsmessage('修改user表结构 ... 完成'); }
function runquery($sql, $tablepre, $db) { global $lang, $tablepre, $db; require_once 'install_lang.php'; if (!isset($sql) || empty($sql)) { return; } $orig_tablepre = "keke_"; $sql = str_replace("\r", "\n", str_replace(' ' . $orig_tablepre, ' ' . $tablepre, $sql)); $sql = str_replace("\r", "\n", str_replace(' `' . $orig_tablepre, ' `' . $tablepre, $sql)); $ret = array(); $num = 0; foreach (explode(";\n", trim($sql)) as $query) { $ret[$num] = ''; $queries = explode("\n", trim($query)); foreach ($queries as $query) { $ret[$num] .= isset($query[0]) && $query[0] == '#' || isset($query[1]) && isset($query[1]) && $query[0] . $query[1] == '--' ? '' : $query; } $num++; } unset($sql); foreach ($ret as $query) { $query = trim($query); $info = ''; if ($query) { if (substr($query, 0, 12) == 'CREATE TABLE') { $name = preg_replace("/CREATE TABLE \\`([a-z0-9_]+)\\` .*/is", "\\1", $query); showjsmessage($lang['create_table'] . ' ' . $name . ' ... ' . $lang['succeed']); $db->query(createtable($query)); } else { $db->query($query); } $info .= $query . "\n"; } } return $info; }
if ($limit > 1000) { $limit = 1000; } $data_list = $db->query("SELECT id,site_name,name FROM {$table} LIMIT " . $begin . ',' . $limit); showjsmessage("开始更新数据表 goods {$begin} 到 " . ($begin + $limit) . " 行"); $data_count = count($data_list); for ($j = 0; $j < $data_count; $j++) { $data = $data_list[$j]; $db->query('INSERT INTO ' . $table_match . ' (id,content) VALUES(' . $data['id'] . ',\'' . segmentToUnicode(clearSymbol($data['site_name'] . $data['name'])) . '\')'); } showjsmessage("更新数据表 goods {$begin} 到 " . ($begin + $limit) . " 行 成功"); if ($limit < 1000) { showjsmessage(U('Index/updatetable', array('table' => 'area', 'begin' => 0)), 5); exit; } else { showjsmessage(U('Index/updatetable', array('table' => 'goods', 'begin' => $begin + $limit)), 5); exit; } } /** * utf8字符转Unicode字符 * @param string $char 要转换的单字符 * @return void */ function utf8ToUnicode($char) { switch (strlen($char)) { case 1: return ord($char); case 2: $n = (ord($char[0]) & 0x3f) << 6;
function runquery($sql) { global $lang, $db, $multitable; if (!isset($sql) || empty($sql)) { return; } $sql = str_replace("\r", "\n", $sql); $ret = array(); $num = 0; foreach (explode(";\n", trim($sql)) as $query) { $ret[$num] = ''; $queries = explode("\n", trim($query)); foreach ($queries as $query) { $ret[$num] .= isset($query[0]) && $query[0] == '#' || isset($query[1]) && isset($query[1]) && $query[0] . $query[1] == '--' ? '' : $query; } $num++; } unset($sql); foreach ($ret as $query) { $query = trim($query); if ($query) { if (substr($query, 0, 12) == 'CREATE TABLE') { if (false !== strpos($query, '__tblname__')) { if ($multitable > 0) { $prefixs = array(); $prefixs = genPrefix(); foreach ($prefixs as $v) { $name = "user_" . $v; $new_sql = str_replace("__tblname__", $name, $query); showjsmessage(lang('create_table') . ' ' . $name . ' ... ' . lang('succeed')); $db->query("DROP TABLE IF EXISTS `{$name}`;"); $db->query(createtable($new_sql)); } } else { $name = "user"; $new_sql = str_replace("__tblname__", $name, $query); showjsmessage(lang('create_table') . ' ' . $name . ' ... ' . lang('succeed')); $db->query("DROP TABLE IF EXISTS `{$name}`;"); $db->query(createtable($new_sql)); } } else { $name = preg_replace("/CREATE TABLE IF NOT EXISTS ([`a-z0-9_]+) .*/is", "\\1", $query); showjsmessage(lang('create_table') . ' ' . $name . ' ... ' . lang('succeed')); $db->query(createtable($query)); } } else { $db->query($query); } } } }
function runquery($sql) { global $lang, $dbcharset, $tablepre, $db, $config; $sql = str_replace(array("\r\n", "\r"), "\n", str_replace('`jishigou_', "`" . $config['db_table_prefix'], $sql)); $ret = array(); $num = 0; foreach (explode(";\n", trim($sql)) as $query) { $queries = explode("\n", trim($query)); foreach ($queries as $query) { $ret[$num] .= $query[0] == '#' || $query[0] . $query[1] == '--' ? '' : $query . ' '; } $num++; } unset($sql); foreach ($ret as $query) { $query = trim($query); if ($query) { $_msg = ''; $name = preg_replace("/(?:CREATE TABLE|REPLACE INTO|INSERT INTO)[\\w\\s`]*?([a-z0-9_]+)`?\\s?.*/is", "\\1", $query); $w12 = trim(strtoupper(substr($query, 0, 12))); if ($w12 == 'CREATE TABLE') { $ex = ''; if ($config['table_partitions_num'] > 1) { $tpname = str_replace($config['db_table_prefix'], '', $name); $partitions = array('members', 'memberfields', 'topic', 'topic_more', 'topic_reply'); if (mysql_get_server_info() >= '5.1' && in_array($tpname, $partitions)) { if ($tpname == 'members' || $tpname == 'memberfields') { $ex = ' PARTITION BY HASH (uid) PARTITIONS ' . $config['table_partitions_num']; } if ($tpname == 'topic' || $tpname == 'topic_more' || $tpname == 'topic_reply') { $ex = ' PARTITION BY HASH (tid) PARTITIONS ' . $config['table_partitions_num']; } } } $sql = createtable($query, $dbcharset, $ex); if ($ex) { $_ret = $db->query($sql, 'SILENT'); if (!$_ret) { $errno = $db->errno(); if (1289 == $errno || 1290 == $errno || false !== strpos(strtolower($db->error()), 'partition')) { $sql = createtable($query, $dbcharset, ''); $db->query($sql); } else { $db->halt('MySQL Query Error', $sql); } } } else { $db->query($sql); } $_msg = $lang['create_table']; } else { $db->query($query); if (false !== strpos($w12, ' INTO')) { $_msg = $lang['db_insert']; } } if ($name && $_msg) { showjsmessage($_msg . ' ' . $name . ' ... ' . $lang['succeed']); } } } }
function runquery($sql) { global $lang, $dbcharset, $tablepre, $db; $sql = str_replace("\r", "\n", str_replace(' onez_', ' ' . $tablepre, $sql)); $ret = array(); $num = 0; foreach (explode(";\n", trim($sql)) as $query) { $queries = explode("\n", trim($query)); foreach ($queries as $query) { $ret[$num] .= $query[0] == '#' || $query[0] . $query[1] == '--' ? '' : $query; } $num++; } unset($sql); foreach ($ret as $query) { $query = trim($query); if ($query) { if (substr($query, 0, 12) == 'CREATE TABLE') { $name = preg_replace("/CREATE TABLE ([a-z0-9_]+) .*/is", "\\1", $query); showjsmessage($lang['create_table'] . ' ' . $name . ' ... ' . $lang['succeed']); $db->query(createtable($query, $dbcharset)); } else { $db->query($query); } } } }
/** * 执行SQL脚本文件 * * @param array $filelist * @return string */ private function restore($file) { $db = $this->getDB(); $sql = file_get_contents($file); $sql = $this->remove_comment($sql); $sql = trim($sql); $bln = true; $tables = array(); //若非UTF-8,则转化为UTF-8 if (!$this->is_utf8($sql)) { $sql = $this->to_utf8($sql); } $segmentSql = explode(";\r", $sql); $segmentSql = str_replace("\r", '', $segmentSql); unset($segmentSql[0]); $table = ""; foreach ($segmentSql as $k => $itemSql) { $itemSql = trim(str_replace("%DB_PREFIX%", C('DB_PREFIX'), $itemSql)); if (!$itemSql) { continue; } if (strtoupper(substr($itemSql, 0, 12)) == 'CREATE TABLE') { $table = preg_replace("/CREATE TABLE (?:IF NOT EXISTS |)(?:`|)([a-z0-9_]+)(?:`|).*/is", "\\1", $itemSql); if (!in_array($table, $tables)) { $tables[] = $table; } if ($db->query($itemSql) === false) { $bln = false; showjsmessage("建立数据表 " . $table . " ... 失败", 1); break; } else { showjsmessage("建立数据表 " . $table . " ... 成功"); } } elseif (strtoupper(substr(trim($itemSql), 0, 11)) == 'ALTER TABLE' && strpos(strtoupper($itemSql), 'ADD') !== FALSE) { //如果字段已经存在就不执行 $matches = array(); preg_match_all('/ALTER TABLE(.*)ADD(.*) /i', $itemSql, $matches); $table_name = trim($matches[1][0]); $column_sql = explode(' ', trim($matches[2][0])); $column = trim($column_sql[0]); if (strpos(strtoupper($column), 'COLUMN') !== FALSE) { $column = trim($column_sql[1]); } $result = $db->query("DESCRIBE {$table_name} {$column}"); //获取字段信息 if (empty($result[0])) { //若字段不存在就执行 if ($db->query($itemSql) === false) { $bln = false; showjsmessage("执行查询 " . $itemSql . " ... 失败", 1); break; } } else { showjsmessage("表 " . $table_name . "中的" . $column . "已经存在 ... 跳过", 2); } } else { if ($db->query($itemSql) === false) { echo $itemSql; $bln = false; showjsmessage("执行查询 " . $itemSql . " ... 失败", 1); break; } } } return $bln; }
} $yearmonth = date('Ym_', time()); loginit($yearmonth . 'illegallog'); loginit($yearmonth . 'cplog'); loginit($yearmonth . 'errorlog'); dir_clear(ROOT_PATH . './data/template'); dir_clear(ROOT_PATH . './data/cache'); foreach ($serialize_sql_setting as $k => $v) { $v = addslashes(serialize($v)); $db->query("REPLACE INTO {$tablepre}setting VALUES ('{$k}', '{$v}')"); } if ($runqueryerror) { showjsmessage('<span class="red">' . $lang['error_quit_msg'] . '</span>'); exit; } showjsmessage('系统数据安装成功!请点击下一步设置管理员</span>'); echo '<script type="text/javascript">function setlaststep() {document.getElementById("laststep").disabled=false;}</script><script type="text/javascript">setTimeout(function(){window.location=\'index.php?step=4\'}, 30000);setlaststep();</script>' . "\r\n"; show_footer(); } show_form($form_db_init_items, $error_msg); } elseif ($method == 'admin_init') { $submit = true; $adminemail = '*****@*****.**'; $error_msg = array(); if (isset($form_admin_init_items) && is_array($form_admin_init_items)) { foreach ($form_admin_init_items as $key => $items) { ${$key} = getgpc($key, 'p'); if (!isset(${$key}) || !is_array(${$key})) { $submit = false; break; }
function runquery($sql) { global $lang, $tablepre, $db; if(!isset($sql) || empty($sql)) return; $sql = str_replace("\r", "\n", str_replace('tp_', $tablepre, $sql)); $ret = array(); $num = 0; foreach(explode(";\n", trim($sql)) as $query) { $ret[$num] = ''; $queries = explode("\n", trim($query)); foreach($queries as $query) { $ret[$num] .= (isset($query[0]) && $query[0] == '#') || (isset($query[1]) && isset($query[1]) && $query[0].$query[1] == '--') ? '' : $query; } $num++; } unset($sql); foreach($ret as $query) { $query = trim($query); if($query) { if(substr($query, 0, 12) == 'CREATE TABLE') { $line = explode('`',$query); $data_name = $line[1]; showjsmessage(lang('create_table').' '.$data_name.' ... '.lang('succeed')); $db->query(droptable($data_name)); /** * 转码 */ if (strtoupper(DBCHARSET) == 'GBK'){ $query = iconv('GBK','UTF-8',$query); } $db->query(createtable($query)); unset($line,$data_name); } else { $db->query($query); } } } }
function Modify_User_Signature() { $uid = (int) $this->Post['uid']; if ($uid < 1) { showjsmessage("请先登录或者注册一个帐号"); } if (jdisallow($uid)) { json_error("您无权修改此用户签名"); } $rets = jclass('misc')->sign_modify($uid, $this->Post['signature']); if (is_array($rets) && $rets['error']) { json_error($rets['msg']); } else { json_result($rets); } }
function installplugin($plugindata, $plugin_info) { global $lang, $dbcharset, $tablepre, $db; $plugindata = preg_replace("/(#.*\\s+)*/", '', $plugindata); $pluginarray = daddslashes(unserialize(base64_decode($plugindata)), 1); $query = $db->query("SELECT pluginid FROM {$tablepre}plugins WHERE identifier='{$pluginarray[plugin][identifier]}' LIMIT 1"); if ($db->num_rows($query)) { showjsmessage('插件 ' . $plugin_info . ' 已安装 ... 跳过'); } else { $sql1 = $sql2 = $comma = ''; foreach ($pluginarray['plugin'] as $key => $val) { if ($key == 'directory') { //compatible for old versions $val .= !empty($val) && substr($val, -1) != '/' ? '/' : ''; } $sql1 .= $comma . $key; $sql2 .= $comma . '\'' . $val . '\''; $comma = ','; } $db->query("INSERT INTO {$tablepre}plugins ({$sql1}) VALUES ({$sql2})"); $pluginid = $db->insert_id(); foreach (array('hooks', 'vars') as $pluginconfig) { if (is_array($pluginarray[$pluginconfig])) { foreach ($pluginarray[$pluginconfig] as $config) { $sql1 = 'pluginid'; $sql2 = '\'' . $pluginid . '\''; foreach ($config as $key => $val) { $sql1 .= ',' . $key; $sql2 .= ',\'' . $val . '\''; } $db->query("INSERT INTO {$tablepre}plugin{$pluginconfig} ({$sql1}) VALUES ({$sql2})"); } } } showjsmessage('正在安装插件 ' . $plugin_info . ' ... 成功'); } }
$fp = fopen($sqlfile, 'rb'); $sql = fread($fp, filesize($sqlfile)); fclose($fp); runquery($sql); runquery($extrasql); dir_clear('./data/templates'); dir_clear('./data/cache'); echo '<script type="text/javascript">document.getElementById("laststep").disabled = false; </script>' . "\r\n"; echo '<script type="text/javascript">document.getElementById("laststep").value = \'下一步\'; </script>' . "\r\n"; } elseif ($action == 'user') { $db = new dbstuff(); $db->connect($dbhost, $dbuser, $dbpw, $dbname, $pconnect); $db->select_db($dbname); $query = $db->query("SELECT * FROM {$tablepre}members WHERE uid='1 Babel'"); if (mysql_num_rows($query) > 0) { showjsmessage('用户已经创建,请继续安装'); } else { if ($_POST['saveconfig']) { $username = strtolower(addslashes(trim(stripslashes($_POST['username'])))); $email = htmlspecialchars($_POST['email']); $password = md5($_POST['password']); $db->query("INSERT INTO {$tablepre}members (username, password, adminid, groupid, regip, regdate, lastvisit, lastactivity, email, dateformat, timeformat, timeoffset ,avatar)\r\n\t\t\t\tVALUES ('{$username}', '{$password}', '1', '1', 'hidden', '{$timestamp}', '{$timestamp}', '{$timestamp}', '{$email}', '0000-00-00', '0', '9999', '')"); redirect("{$installfile}?action=user"); } } if (mysql_num_rows($query) > 0) { ?> <tr><td><hr noshade align="center" width="100%" size="1"></td></tr> <tr><td align="center"><br /> 用户已创建,请继续安装<br /><br /> <form method="post" action="<?php
exit; } $t = explode("@", $mailadres); if (!$t[1]) { echo "<script>alert('电子邮件格式不正确!');location.href='install.php?step=3'</script>"; exit; } if ($password1 != $password2) { echo "<script>alert('两次输入的密码不正确!');location.href='install.php?step=3'</script>"; exit; } if ($password1 == $password2 && $password1 && $password2) { $web_name3 = "EasyTalk 安装"; include $template->getfile('install.htm'); $sql = file_get_contents($sqlfile); $db = new dbstuff(); $db->connect($server, $db_username, $db_password, $db_name, $pconnect, true, "GBK"); @mysql_query("set names GBK"); runquery($sql); $db->query("INSERT INTO et_users (user_name,password,mailadres,signupdate,isadmin) VALUES ('{$username}','{$password2}','{$mailadres}','{$addtime}','1')"); showjsmessage("管理员账号写入成功!"); @touch($lockfile); exit; } else { echo "<script>alert('密码输入不正确,请重新输入!');location.href='install.php?step=3'</script>"; exit; } } //模板和Foot $web_name3 = "EasyTalk 安装"; include $template->getfile('install.htm');
function install_testdata($username, $uid) { global $db, $tablepre, $testdatacontent; if(empty($testdatacontent)) return; showjsmessage(lang('install_test_data')." ... ".lang('succeed')); $threads = 0; foreach($testdatacontent as $val) { $db->query("INSERT INTO {$tablepre}threads (fid, subject, author, authorid, dateline, lastpost, lastposter) VALUES (2, '".addslashes($val['subject'])."', '$username', '$uid', ".time().", ".time().", '$username')"); if($tid = $db->insert_id()) { $threads++; $db->query("INSERT INTO {$tablepre}posts (fid, tid, first, subject, author, authorid, dateline, message) VALUES (2, $tid, 1, '".addslashes($val['subject'])."', '$username', '$uid', ".time().", '".addslashes($val['message'])."')"); } } $db->query("UPDATE {$tablepre}forums SET threads=$threads, posts=$threads, lastpost='$tid\t$val[subject]\t".time()."\t$username' WHERE fid=2"); $db->query("UPDATE {$tablepre}members SET threads=$threads, posts=$threads WHERE uid='$uid'"); }
function dir_clear($dir) { global $lang; showjsmessage($lang['clear_dir'] . ' ' . str_replace(S_ROOT, '', $dir)); if ($directory = @dir($dir)) { while ($entry = $directory->read()) { $filename = $dir . '/' . $entry; if (is_file($filename)) { @unlink($filename); } } $directory->close(); @touch($dir . '/index.htm'); } }
if (substr($sql, 0, 12) == 'CREATE TABLE') { $t_name = preg_replace("/CREATE TABLE `([a-z0-9_]+)` .*/is", "\\1", $sql); if (@$db->execute($sql)) { showjsmessage('<ol>正在创建数据表:' . $t_name . ' … <img src="images/ok.png" /></ol>'); } else { $result = false; showjsmessage('<ol><font color="#FF0000">正在创建数据表:' . $t_name . ' … </font><img src="images/not.png" /></ol>'); } } else { @$db->execute($sql); } } if ($result) { showjsmessage('<ol><font color="#000000">数据库安装成功,请继续下一步安装。</font></ol>'); } else { showjsmessage('<ol><font color="#FF0000">数据库没有正确安装或是安装过程中出现异常,请检查连接参数设置是否正确。</font></ol>'); } ?> <div id="button"><table width="100%"><tr><td height="80" align="center">正在安装数据库,请稍候 …</td></tr></table></div> <script type="text/javascript"> var table = '<table width="100%"><tr><td width="80" height="80"> </td>'; table += '<td align="center"><a href="index.php?step=3" onfocus="this.blur()"><img src="images/button_prev.png" width="112" height="35" /></a></td>'; <?php if ($result) { ?> table += '<td align="center"><a href="index.php?step=5<?php if ($_GET['demo'] == 1) { echo '&demo=1'; } ?> " onfocus="this.blur()"><img src="images/button_next.png" width="112" height="35" /></a></td>';<?php
function cleardir($dir) { global $lang; showjsmessage(lang('clear_dir') . ' ' . str_replace(ROOTDIR, '', $dir)); dir_clear($dir); }
function install_testdata($username, $uid) { global $_G, $db, $tablepre; showjsmessage(lang('install_test_data') . " ... " . lang('succeed')); $sqlfile = ROOT_PATH . './install/data/common_district_{#id}.sql'; for ($i = 1; $i < 4; $i++) { $sqlfileid = str_replace('{#id}', $i, $sqlfile); if (file_exists($sqlfileid)) { $sql = file_get_contents($sqlfileid); $sql = str_replace("\r\n", "\n", $sql); runquery($sql); } } }
function insert_config() { global $tablepre, $db; $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, 0, 'site_info', 'group', '', '', '', 1)"; $db->query($sql); $group_site_info_id = $db->insert_id(); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, 0, 'smtp', 'group', '', '', '', 1)"; $db->query($sql); $group_smtp_id = $db->insert_id(); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, 0, 'hidden', 'hidden', '', '', '', 1)"; $db->query($sql); $group_hidden_id = $db->insert_id(); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, 0, 'sms', 'group', '', '', '', 1)"; $db->query($sql); $group_sms_id = $db->insert_id(); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, 0, 'payment', 'group', '', '', '', 1)"; $db->query($sql); $group_payment_id = $db->insert_id(); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, 0, 'open_platform', 'group', '', '', '', 24)"; $db->query($sql); $group_open_platform_id = $db->insert_id(); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_hidden_id}', 'captcha', 'hidden', '', '', '', 1)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_hidden_id}', 'captcha_width', 'hidden', '', '', '', 1)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_hidden_id}', 'captcha_height', 'hidden', '', '', '', 1)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_smtp_id}', 'smtp_host', 'text', '', '', '', 1)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_smtp_id}', 'smtp_port', 'text', '', '', '25', 1)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_smtp_id}', 'smtp_user', 'text', '', '', '', 1)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_smtp_id}', 'smtp_pass', 'password', '', '', '', 1)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_smtp_id}', 'smtp_mail', 'text', '', '', '', 1)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_smtp_id}', 'mail_charset', 'select', 'UTF8,GB2312,BIG5', '', 'UTF8', 1)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_smtp_id}', 'mail_service', 'select', '0,1', '', '1', 0)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_site_info_id}', 'site_name', 'text', '', '', 'TP-COUPON', 1)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_site_info_id}', 'site_title', 'text', '', '', '中国领先的优惠券平台', 2)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_site_info_id}', 'site_keywords', 'textarea', '', '', '网购 优惠券 京东优惠券 当当优惠券 凡客优惠券', 3)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_site_info_id}', 'site_description', 'textarea', '', '', '中国领先的优惠券平台', 4)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_site_info_id}', 'time_format', 'text', '', '', 'Y-m-d H:i:s', 6)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_site_info_id}', 'date_format', 'text', '', '', 'Y-m-d', 5)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_site_info_id}', 'timezone', 'options', '-12,-11,-10,-9,-8,-7,-6,-5,-4,-3.5,-3,-2,-1,0,1,2,3,3.5,4,4.5,5,5.5,5.75,6,6.5,7,8,9,9.5,10,11,12', '', '8', 7)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_site_info_id}', 'open_gzip', 'select', '0,1', '', '1', 8)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_site_info_id}', 'thumb_width', 'text', '', '', '75', 9)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_site_info_id}', 'thumb_height', 'text', '', '', '75', 10)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_site_info_id}', 'image_water_path', 'text', '', '', './Public/Images/logo.png', 11)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_site_info_id}', 'site_domain', 'text', '', '', '', 12)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_site_info_id}', 'data_cache_time', 'text', '', '', '2', 13)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_site_info_id}', 'service_qq', 'text', '', '', '89249294', 14)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_site_info_id}', 'weibo_sina', 'text', '', '', 'jihaoju', 15)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_site_info_id}', 'weibo_qq', 'text', '', '', 'jihaoju', 16)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_site_info_id}', 'icp_number', 'text', '', '', '', 19)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_site_info_id}', 'code_in_secret', 'text', '', '', '4', 22)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_site_info_id}', 'url_rewrite', 'options', '0,1', '', '0', 21)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_site_info_id}', 'invite_credit', 'text', '', '', '6', 23)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_site_info_id}', 'statis_code', 'textarea', '', '', '', 23)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_site_info_id}', 'max_left_days', 'text', '', '', '2', '32')"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_sms_id}', 'sms_url_send', 'text', '', '', '', 1)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_sms_id}', 'sms_url_sendtime', 'text', '', '', '', 1)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_sms_id}', 'sms_url_get', 'text', '', '', '', 1)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_sms_id}', 'sms_cdkey', 'text', '', '', '', 1)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_sms_id}', 'sms_password', 'text', '', '', '', 1)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_payment_id}', 'alipay_partner', 'text', '', '', '', 16)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_payment_id}', 'alipay_key', 'password', '', '', '', 17)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_payment_id}', 'alipay_seller_email', 'text', '', '', '', 18)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_payment_id}', 'alipay_type', 'options', 'direct,warrant', '', 'warrant', 20)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_open_platform_id}', 'qq_appid', 'text', '', '', '', 25)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_open_platform_id}', 'qq_appkey', 'text', '', '', '', 26)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_open_platform_id}', 'qq_open', 'select', '0,1', '', '0', 27)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_open_platform_id}', 'sina_wb_akey', 'text', '', '', '', 28)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_open_platform_id}', 'sina_wb_skey', 'text', '', '', '', 29)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_open_platform_id}', 'sina_wb_office_id', 'text', '', '', '0', 30)"; $db->query($sql); $sql = "INSERT INTO `" . $tablepre . "site_config` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`)\r\n\t\t\t VALUES(null, '{$group_open_platform_id}', 'sina_wb_open', 'select', '0,1', '', '0', 31)"; $db->query($sql); showjsmessage('初始化系统设置 ... 成功'); }
$mdl_setting->set_conf('system.show_process_info', false); $mdl_setting->set_conf('system.language', INS_LANG); $mdl_setting->set_conf('system.timezone', 8); $mdl_setting->set_conf('system.current_theme', 'sense'); $mdl_setting->set_conf('site.title', $sitename); $mdl_setting->set_conf('site.url', $siteurl); $mdl_setting->set_conf('site.footer', ''); $mdl_setting->set_conf('site.email', $email); $mdl_setting->set_conf('site.share_title', lang('share_title')); $mdl_setting->set_conf('site.keywords', lang('site_keywords')); $mdl_setting->set_conf('site.description', lang('site_desc')); showjsmessage(lang('update_user_setting')); $plugin =& loader::lib('plugin'); $plugin->install_plugin('copyimg'); $plugin->enable_plugin('copyimg'); showjsmessage(lang('install_default_plugins')); echo '<script type="text/javascript">document.getElementById("laststep").disabled=false;document.getElementById("laststep").value = \'' . lang('installed_complete') . '\';</script><script type="text/javascript">setTimeout(function(){window.location=\'index.php?method=complete\'}, 2000);</script>' . "\r\n"; @touch(ROOTDIR . 'conf/install.lock'); getstatinfo(array('email' => $email)); show_footer(); } else { show_form($form_db_init_items, $error_msg); } } elseif ($method == 'complete') { $step = 4; show_header(); echo '<ul style="line-height: 200%; margin-left: 30px;">'; echo '<li><a href="../">' . lang('install_succeed') . '</a><br>'; echo '<script>setTimeout(function(){window.location=\'../\'}, 2000);</script>' . lang('auto_redirect') . '</li>'; echo '</ul></div>'; show_footer();
/** * 执行SQL脚本文件 * * @param array $filelist * @return string */ private function restore($file) { $db = $this->getDB(); $sql = file_get_contents($file); $sql = $this->remove_comment($sql); $sql = trim($sql); $bln = true; $tables = array(); $sql = str_replace("\r", '', $sql); $segmentSql = explode(";\n", $sql); unset($segmentSql[0]); $table = ""; foreach ($segmentSql as $k => $itemSql) { $itemSql = trim(str_replace("%DB_PREFIX%", C('DB_PREFIX'), $itemSql)); if (strtoupper(substr($itemSql, 0, 12)) == 'CREATE TABLE') { $table = preg_replace("/CREATE TABLE (?:IF NOT EXISTS |)(?:`|)([a-z0-9_]+)(?:`|).*/is", "\\1", $itemSql); if (!in_array($table, $tables)) { $tables[] = $table; } if ($db->query($itemSql) === false) { $bln = false; showjsmessage("建立数据表 " . $table . " ... 失败", 1); break; } else { showjsmessage("建立数据表 " . $table . " ... 成功"); } } else { if ($db->query($itemSql) === false) { $bln = false; showjsmessage("执行查询 " . $itemSql . " ... 失败", 1); break; } } } return $bln; }
/** * 执行SQL脚本文件 * * @param array $filelist * @return string */ private function restore($file, $db_config) { set_time_limit(0); $host = $db_config['DB_HOST']; if (!empty($db_config['DB_PORT'])) { $host = $db_config['DB_HOST'] . ':' . $db_config['DB_PORT']; } Vendor("mysql"); $db = new mysqldb(array('dbhost' => $host, 'dbuser' => $db_config['DB_USER'], 'dbpwd' => $db_config['DB_PWD'], 'dbname' => $db_config['DB_NAME'], 'dbcharset' => 'utf8', 'pconnect' => 0)); $sql = file_get_contents($file); $sql = $this->remove_comment($sql); $sql = trim($sql); $bln = true; $tables = array(); $sql = str_replace("\r", '', $sql); $segmentSql = explode(";\n", $sql); $table = ""; foreach ($segmentSql as $k => $itemSql) { $itemSql = trim(str_replace("%DB_PREFIX%", $db_config['DB_PREFIX'], $itemSql)); if (strtoupper(substr($itemSql, 0, 12)) == 'CREATE TABLE') { $table = preg_replace("/CREATE TABLE (?:IF NOT EXISTS |)(?:`|)([a-z0-9_]+)(?:`|).*/is", "\\1", $itemSql); if (!in_array($table, $tables)) { $tables[] = $table; } if ($db->query($itemSql) === false) { $bln = false; showjsmessage("建立数据表 " . $table . " ... 失败", 1); break; } else { showjsmessage("建立数据表 " . $table . " ... 成功"); } } else { if ($db->query($itemSql) === false) { $bln = false; showjsmessage("添加数据表 " . $table . " ... 数据失败", 1); break; } } } return $bln; }
function runquery($sql) { global $lang, $tablepre, $db; if (!isset($sql) || empty($sql)) { return; } $sql = str_replace("\r", "\n", str_replace(' ' . ORIG_TABLEPRE, ' ' . $tablepre, $sql)); $ret = array(); $num = 0; foreach (explode(";\n", trim($sql)) as $query) { $ret[$num] = ''; $queries = explode("\n", trim($query)); foreach ($queries as $query) { $ret[$num] .= isset($query[0]) && $query[0] == '#' || isset($query[1]) && isset($query[1]) && $query[0] . $query[1] == '--' ? '' : $query; } $num++; } unset($sql); foreach ($ret as $query) { $query = trim($query); if ($query) { if (substr($query, 0, 12) == 'CREATE TABLE') { $name = preg_replace("/CREATE TABLE ([a-z0-9_]+) .*/is", "\\1", $query); showjsmessage(lang('create_table') . ' ' . $name . ' ... ' . lang('succeed')); $db->query(createtable($query)); } else { $db->query($query); } } } }
if (count($city_id) > 0) { $city_id = $city_id[0]['id']; } else { $city_id = 0; } if ($city_id > 0) { $city_ids[$key] = $city_id; foreach ($citys as $city) { $parent_ids[$key][$city] = $index; $sql .= $jg . "({$index},'{$city}',{$city_id},0)"; $index++; $jg = ','; } } } foreach ($citys_data as $key => $citys) { $city_id = intval($city_ids[$key]); if ($city_id > 0) { foreach ($citys as $city) { $parent_id = $parent_ids[$key][$city]; $areas = $areas_data[$key][$city]; foreach ($areas as $area) { $sql .= $jg . "({$index},'{$area}',{$city_id},{$parent_id})"; $index++; } } } } $db->query($sql); showjsmessage("更新完成", 4); exit;
function runquery($sql, $db_prefix, $db) { // global $lang, $tablepre, $db; if (!isset($sql) || empty($sql)) { return; } $sql = str_replace("\r", "\n", str_replace('#__', $db_prefix, $sql)); $ret = array(); $num = 0; foreach (explode(";\n", trim($sql)) as $query) { $ret[$num] = ''; $queries = explode("\n", trim($query)); foreach ($queries as $query) { $ret[$num] .= isset($query[0]) && $query[0] == '#' || isset($query[1]) && isset($query[1]) && $query[0] . $query[1] == '--' ? '' : $query; } $num++; } unset($sql); foreach ($ret as $query) { $query = trim($query); if ($query) { if (substr($query, 0, 12) == 'CREATE TABLE') { $line = explode('`', $query); $data_name = $line[1]; showjsmessage('数据表 ' . $data_name . ' ... 创建成功'); $db->query(droptable($data_name)); /** * 转码 */ if (strtoupper(DBCHARSET) == 'GBK') { $query = iconv('GBK', 'UTF-8', $query); } $db->query($query); unset($line, $data_name); } else { $db->query($query); } } } }
function runquery($sql) { global $tablepre, $db, $default_appurl; if (!isset($sql) || empty($sql)) { return; } $sql = str_replace("\r", "\n", str_replace(' qcs_', ' ' . $tablepre, $sql)); $sql = str_replace("\r", "\n", str_replace(' `qcs_', ' `' . $tablepre, $sql)); $ret = array(); $num = 0; foreach (explode(";\n", trim($sql)) as $query) { $ret[$num] = ''; $queries = explode("\n", trim($query)); foreach ($queries as $query) { $ret[$num] .= isset($query[0]) && $query[0] == '#' || isset($query[1]) && isset($query[1]) && $query[0] . $query[1] == '--' ? '' : $query; } $num++; } unset($sql); foreach ($ret as $query) { $query = trim($query); // $query=str_replace('__PUBLIC__',$default_appurl.'/Public',$query); if ($query) { if (substr($query, 0, 12) == 'CREATE TABLE') { $name = preg_replace("/CREATE TABLE IF NOT EXISTS `([a-z0-9_]+)` .*/is", "\\1", $query); showjsmessage('建立数据表 ' . $name . ' ... 成功'); $db->query(createtable($query)); } else { $db->query($query); } } } }