国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

155 řádky
4.8KB

  1. <?php
  2. /**
  3. * SQL命令工具
  4. *
  5. * @version $id:sys_sql_query.php 22:28 2010年7月20日 tianya $
  6. * @package DedeBIZ.Administrator
  7. * @copyright Copyright (c) 2022 DedeBIZ.COM
  8. * @license GNU GPL v2 (https://www.dedebiz.com/license)
  9. * @link https://www.dedebiz.com
  10. */
  11. require(dirname(__FILE__)."/config.php");
  12. if (DEDEBIZ_SAFE_MODE) {
  13. die(DedeAlert("系统已启用安全模式,无法使用当前功能",ALERT_DANGER));
  14. }
  15. CheckPurview('sys_Data');
  16. if (empty($dopost)) $dopost = '';
  17. //查看表结构
  18. if ($dopost == "viewinfo") {
  19. CheckCSRF();
  20. if (empty($tablename)) {
  21. echo "没有指定表名";
  22. } else {
  23. $dsql->SetQuery("SHOW CREATE TABLE ".$dsql->dbName.".".$tablename);
  24. $dsql->Execute('me');
  25. $row2 = $dsql->GetArray('me', MYSQL_BOTH);
  26. $ctinfo = $row2[1];
  27. echo "<xmp>".trim($ctinfo)."</xmp>";
  28. }
  29. exit();
  30. }
  31. //优化表
  32. else if ($dopost == "opimize") {
  33. CheckCSRF();
  34. if (empty($tablename)) {
  35. echo "没有指定表名";
  36. } else {
  37. $rs = $dsql->ExecuteNoneQuery("OPTIMIZE TABLE `$tablename`");
  38. if ($rs) echo "执行优化表".$tablename."完成<br>";
  39. else echo "执行优化表".$tablename."失败,原因是:".$dsql->GetError();
  40. }
  41. exit();
  42. }
  43. //优化全部表
  44. else if ($dopost == "opimizeAll") {
  45. CheckCSRF();
  46. $dsql->SetQuery("SHOW TABLES");
  47. $dsql->Execute('t');
  48. while ($row = $dsql->GetArray('t', MYSQL_BOTH)) {
  49. $rs = $dsql->ExecuteNoneQuery("OPTIMIZE TABLE `{$row[0]}`");
  50. if ($rs) {
  51. echo "优化表{$row[0]}完成<br>";
  52. } else {
  53. echo "优化表{$row[0]}失败,原因是: ".$dsql->GetError();
  54. }
  55. }
  56. exit();
  57. }
  58. //修复表
  59. else if ($dopost == "repair") {
  60. CheckCSRF();
  61. if (empty($tablename)) {
  62. echo "没有指定表名";
  63. } else {
  64. $rs = $dsql->ExecuteNoneQuery("REPAIR TABLE `$tablename`");
  65. if ($rs) echo "修复表".$tablename."完成<br>";
  66. else echo "修复表".$tablename."失败,原因是:".$dsql->GetError();
  67. }
  68. exit();
  69. }
  70. //修复全部表
  71. else if ($dopost == "repairAll") {
  72. CheckCSRF();
  73. $dsql->SetQuery("Show Tables");
  74. $dsql->Execute('t');
  75. while ($row = $dsql->GetArray('t', MYSQL_BOTH)) {
  76. $rs = $dsql->ExecuteNoneQuery("REPAIR TABLE `{$row[0]}`");
  77. if ($rs) {
  78. echo "修复表{$row[0]}完成<br>";
  79. } else {
  80. echo "修复表{$row[0]}失败,原因是: ".$dsql->GetError();
  81. }
  82. }
  83. exit();
  84. }
  85. //执行SQL语句
  86. else if ($dopost == "query") {
  87. CheckCSRF();
  88. $mysqlVersions = explode('.',trim($row[0]));
  89. $mysqlVersion = $mysqlVersions[0].".".$mysqlVersions[1];
  90. $sqlquery = trim(stripslashes($sqlquery));
  91. if (preg_match("#drop(.*)table#i", $sqlquery) || preg_match("#drop(.*)database#", $sqlquery)) {
  92. echo "删除数据表或数据库的语句不允许在这里执行";
  93. exit();
  94. }
  95. if ($mysqlVersion >= 4.1 && preg_match('#CREATE#i', $sqlquery)) {
  96. $sql4tmp = "ENGINE=MyISAM DEFAULT CHARSET=".$$cfg_db_language;
  97. $sqlquery = preg_replace("#TYPE=MyISAM#i", $sql4tmp, $sqlquery);
  98. }
  99. echo '<link rel="stylesheet" href="/static/web/css/bootstrap.min.css">';
  100. //运行查询语句
  101. if (preg_match("#^select #i", $sqlquery)) {
  102. $dsql->SetQuery($sqlquery);
  103. $dsql->Execute();
  104. if ($dsql->GetTotalRow() <= 0) {
  105. echo "运行SQL:{$sqlquery}无返回记录<br>";
  106. } else {
  107. echo "运行SQL:{$sqlquery}共有".$dsql->GetTotalRow()."条记录,最大返回100条";
  108. }
  109. $j = 0;
  110. while ($row = $dsql->GetArray()) {
  111. $j++;
  112. if ($j > 100) {
  113. break;
  114. }
  115. echo "<hr>";
  116. echo "记录:$j";
  117. echo "<hr>";
  118. foreach ($row as $k => $v) {
  119. echo "{$k}:{$v}<br>\r\n";
  120. }
  121. }
  122. exit();
  123. }
  124. if ($querytype == 2) {
  125. //普通的SQL语句
  126. $sqlquery = str_replace("\r", "", $sqlquery);
  127. $sqls = preg_split("#;[ \t]{0,}\n#", $sqlquery);
  128. $nerrCode = '';
  129. $i = 0;
  130. foreach ($sqls as $q) {
  131. $q = trim($q);
  132. if ($q == "") {
  133. continue;
  134. }
  135. $dsql->ExecuteNoneQuery($q);
  136. $errCode = trim($dsql->GetError());
  137. if ($errCode == "") {
  138. $i++;
  139. } else {
  140. $nerrCode .= "执行".$q."出错,错误提示:".$errCode."";
  141. }
  142. }
  143. echo "成功执行{$i}个SQL语句";
  144. echo $nerrCode;
  145. } else {
  146. $dsql->ExecuteNoneQuery($sqlquery);
  147. $nerrCode = trim($dsql->GetError());
  148. echo "成功执行1个SQL语句";
  149. echo $nerrCode;
  150. }
  151. exit();
  152. }
  153. make_hash();
  154. include DedeInclude('templets/sys_sql_query.htm');
  155. ?>