SetQuery("SHOW CREATE TABLE ".$dsql->dbName.".".$tablename);
$dsql->Execute('me');
$row2 = $dsql->GetArray('me', MYSQL_BOTH);
$ctinfo = $row2[1];
echo "
".trim($ctinfo)."";
}
exit();
}
//优化表
else if ($dopost == "opimize") {
CheckCSRF();
if (empty($tablename)) {
echo "没有指定表名";
} else {
$rs = $dsql->ExecuteNoneQuery("OPTIMIZE TABLE `$tablename`");
if ($rs) echo "执行优化表".$tablename."完成
";
else echo "执行优化表".$tablename."失败,原因是:".$dsql->GetError();
}
exit();
}
//优化全部表
else if ($dopost == "opimizeAll") {
CheckCSRF();
$dsql->SetQuery("SHOW TABLES");
$dsql->Execute('t');
while ($row = $dsql->GetArray('t', MYSQL_BOTH)) {
$rs = $dsql->ExecuteNoneQuery("OPTIMIZE TABLE `{$row[0]}`");
if ($rs) {
echo "优化表{$row[0]}完成
";
} else {
echo "优化表{$row[0]}失败,原因是: ".$dsql->GetError();
}
}
exit();
}
//修复表
else if ($dopost == "repair") {
CheckCSRF();
if (empty($tablename)) {
echo "没有指定表名";
} else {
$rs = $dsql->ExecuteNoneQuery("REPAIR TABLE `$tablename`");
if ($rs) echo "修复表".$tablename."完成
";
else echo "修复表".$tablename."失败,原因是:".$dsql->GetError();
}
exit();
}
//修复全部表
else if ($dopost == "repairAll") {
CheckCSRF();
$dsql->SetQuery("Show Tables");
$dsql->Execute('t');
while ($row = $dsql->GetArray('t', MYSQL_BOTH)) {
$rs = $dsql->ExecuteNoneQuery("REPAIR TABLE `{$row[0]}`");
if ($rs) {
echo "修复表{$row[0]}完成
";
} else {
echo "修复表{$row[0]}失败,原因是: ".$dsql->GetError();
}
}
exit();
}
//执行SQL语句
else if ($dopost == "query") {
CheckCSRF();
$mysqlVersions = explode('.',trim($row[0]));
$mysqlVersion = $mysqlVersions[0].".".$mysqlVersions[1];
$sqlquery = trim(stripslashes($sqlquery));
if (preg_match("#drop(.*)table#i", $sqlquery) || preg_match("#drop(.*)database#", $sqlquery)) {
echo "删除数据表或数据库的语句不允许在这里执行";
exit();
}
if ($mysqlVersion >= 4.1 && preg_match('#CREATE#i', $sqlquery)) {
$sql4tmp = "ENGINE=MyISAM DEFAULT CHARSET=".$$cfg_db_language;
$sqlquery = preg_replace("#TYPE=MyISAM#i", $sql4tmp, $sqlquery);
}
echo '';
//运行查询语句
if (preg_match("#^select #i", $sqlquery)) {
$dsql->SetQuery($sqlquery);
$dsql->Execute();
if ($dsql->GetTotalRow() <= 0) {
echo "运行SQL:{$sqlquery}无返回记录
";
} else {
echo "运行SQL:{$sqlquery}共有".$dsql->GetTotalRow()."条记录,最大返回100条";
}
$j = 0;
while ($row = $dsql->GetArray()) {
$j++;
if ($j > 100) {
break;
}
echo "
";
echo "记录:$j";
echo "
";
foreach ($row as $k => $v) {
echo "{$k}:{$v}
\r\n";
}
}
exit();
}
if ($querytype == 2) {
//普通的SQL语句
$sqlquery = str_replace("\r", "", $sqlquery);
$sqls = preg_split("#;[ \t]{0,}\n#", $sqlquery);
$nerrCode = '';
$i = 0;
foreach ($sqls as $q) {
$q = trim($q);
if ($q == "") {
continue;
}
$dsql->ExecuteNoneQuery($q);
$errCode = trim($dsql->GetError());
if ($errCode == "") {
$i++;
} else {
$nerrCode .= "执行".$q."出错,错误提示:".$errCode."";
}
}
echo "成功执行{$i}个SQL语句";
echo $nerrCode;
} else {
$dsql->ExecuteNoneQuery($sqlquery);
$nerrCode = trim($dsql->GetError());
echo "成功执行1个SQL语句";
echo $nerrCode;
}
exit();
}
make_hash();
include DedeInclude('templets/sys_sql_query.htm');
?>