1 Star 0 Fork 96

風哥/ectouch

forked from ectouch/ectouch 
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
sql.php 3.51 KB
一键复制 编辑 原始数据 按行查看 历史
carson 提交于 2018-03-12 09:54 +08:00 . format
<?php
/**
* 会员管理程序
*/
define('IN_ECTOUCH', true);
require(dirname(__FILE__) . '/includes/init.php');
$_POST['sql'] = !empty($_POST['sql']) ? trim($_POST['sql']) : '';
if (!$_POST['sql']) {
$_REQUEST['act'] = 'main';
}
/*------------------------------------------------------ */
//-- 用户帐号列表
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'main') {
admin_priv('sql_query');
assign_query_info();
$smarty->assign('type', -1);
$smarty->assign('ur_here', $_LANG['04_sql_query']);
$smarty->display('sql.htm');
}
if ($_REQUEST['act'] == 'query') {
admin_priv('sql_query');
if (!empty($_POST['sql'])) {
preg_match_all("/(SELECT)/i", $_POST['sql'], $matches);
if (isset($matches[1]) && count($matches[1])>1) {
sys_msg("this sql more than one SELECT ");
}
if (preg_match("/(UPDATE|DELETE|TRUNCATE|ALTER|DROP|FLUSH|INSERT|REPLACE|SET|CREATE|CONCAT)/i", $_POST['sql'])) {
sys_msg("this sql May contain UPDATE,DELETE,TRUNCATE,ALTER,DROP,FLUSH,INSERT,REPLACE,SET,CREATE,CONCAT ");
}
}
assign_sql($_POST['sql']);
assign_query_info();
$smarty->assign('ur_here', $_LANG['04_sql_query']);
$smarty->display('sql.htm');
}
/**
*
*
* @access public
* @param
*
* @return void
*/
function assign_sql($sql)
{
global $db, $smarty, $_LANG;
$sql = stripslashes($sql);
$smarty->assign('sql', $sql);
/* 解析查询项 */
$sql = str_replace("\r", '', $sql);
$query_items = explode(";\n", $sql);
foreach ($query_items as $key=>$value) {
if (empty($value)) {
unset($query_items[$key]);
}
}
/* 如果是多条语句,拆开来执行 */
if (count($query_items) > 1) {
foreach ($query_items as $key=>$value) {
if ($db->query($value, 'SILENT')) {
$smarty->assign('type', 1);
} else {
$smarty->assign('type', 0);
$smarty->assign('error', $db->error());
return;
}
}
return; //退出函数
}
/* 单独一条sql语句处理 */
if (preg_match("/^(?:UPDATE|DELETE|TRUNCATE|ALTER|DROP|FLUSH|INSERT|REPLACE|SET|CREATE)\\s+/i", $sql)) {
if ($db->query($sql, 'SILENT')) {
$smarty->assign('type', 1);
} else {
$smarty->assign('type', 0);
$smarty->assign('error', $db->error());
}
} else {
$data = $db->GetAll($sql);
if ($data === false) {
$smarty->assign('type', 0);
$smarty->assign('error', $db->error());
} else {
$result = '';
if (is_array($data) && isset($data[0]) === true) {
$result = "<table> \n <tr>";
$keys = array_keys($data[0]);
for ($i = 0, $num = count($keys); $i < $num; $i++) {
$result .= "<th>" . $keys[$i] . "</th>\n";
}
$result .= "</tr> \n";
foreach ($data as $data1) {
$result .= "<tr>\n";
foreach ($data1 as $value) {
$result .= "<td>" . $value . "</td>";
}
$result .= "</tr>\n";
}
$result .= "</table>\n";
} else {
$result ="<center><h3>" . $_LANG['no_data'] . "</h3></center>";
}
$smarty->assign('type', 2);
$smarty->assign('result', $result);
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/junchen/ectouch.git
git@gitee.com:junchen/ectouch.git
junchen
ectouch
ectouch
master

搜索帮助