浏览代码

Update sys_sql_query.php

tags/6.5.9
tianya 21 小时前
父节点
当前提交
ab1e259c0a
共有 1 个文件被更改,包括 28 次插入60 次删除
  1. +28
    -60
      src/admin/sys_sql_query.php

+ 28
- 60
src/admin/sys_sql_query.php 查看文件

@@ -22,13 +22,13 @@ if ($dopost == "viewinfo") {
if (empty($tablename)) {
echo "没有指定表名";
} else {
// 获取创建表的 SQL 语句
//获取创建表的SQL语句
$dsql->SetQuery("SELECT sql FROM sqlite_master WHERE type='table' AND name='$tablename'");
$dsql->Execute('me');
$row = $dsql->GetArray('me', SQLITE3_ASSOC);
if ($row) {
$createTableSql = str_replace(" ", "\r\n", $row['sql']);
echo trim($createTableSql) . "\n\n";
echo trim($createTableSql)."\n\n";
}
}
echo '</xmp>';
@@ -57,7 +57,7 @@ else if ($dopost == "opimize") {
if ($rs) {
echo "执行优化表 {$tablename} 完成<br>";
} else {
echo "执行优化表 {$tablename} 失败,原因是:" . $dsql->GetError();
echo "执行优化表 {$tablename} 失败,原因是:".$dsql->GetError();
}
} else {
$rs = $dsql->ExecuteNoneQuery("OPTIMIZE TABLE `$tablename`");
@@ -77,7 +77,7 @@ else if ($dopost == "opimizeAll") {
if ($rs) {
echo "执行数据库完成<br>";
} else {
echo "执行数据库失败,原因是:" . $dsql->GetError();
echo "执行数据库失败,原因是:".$dsql->GetError();
}
} else {
while ($row = $dsql->GetArray('t', MYSQL_BOTH)) {
@@ -91,42 +91,42 @@ else if ($dopost == "opimizeAll") {
}
exit();
}
// 修复表
//修复表
else if ($dopost == "repair") {
CheckCSRF();
if (empty($tablename)) {
echo "没有指定表名";
} else {
if ($cfg_dbtype =='sqlite') {
// SQLite 数据库使用 VACUUM 尝试修复和优化
//SQLite数据库使用VACUUM尝试修复和优化
$rs = $dsql->ExecuteNoneQuery("VACUUM");
if ($rs) {
echo "对表 {$tablename} 尝试修复和优化完成<br>";
} else {
echo "对表 {$tablename} 尝试修复和优化失败,原因是:" . $dsql->GetError();
echo "对表 {$tablename} 尝试修复和优化失败,原因是:".$dsql->GetError();
}
} else {
// SQLite 数据库(如 MySQL)使用 REPAIR TABLE 语句
//非SQLite数据库(如 MySQL)使用REPAIR TABLE语句
$rs = $dsql->ExecuteNoneQuery("REPAIR TABLE `{$tablename}`");
if ($rs) {
echo "修复表 {$tablename} 完成<br>";
} else {
echo "修复表 {$tablename} 失败,原因是:" . $dsql->GetError();
echo "修复表 {$tablename} 失败,原因是:".$dsql->GetError();
}
}
}
exit();
}
// 修复全部表
//修复全部表
else if ($dopost == "repairAll") {
CheckCSRF();
if ($cfg_dbtype =='sqlite') {
// SQLite 数据库使用 VACUUM 尝试修复和优化整个数据库
//SQLite 数据库使用VACUUM尝试修复和优化整个数据库
$rs = $dsql->ExecuteNoneQuery("VACUUM");
if ($rs) {
echo "对所有表尝试修复和优化完成<br>";
} else {
echo "对所有表尝试修复和优化失败,原因是:" . $dsql->GetError();
echo "对所有表尝试修复和优化失败,原因是:".$dsql->GetError();
}
} else {
$dsql->SetQuery("Show Tables");
@@ -136,7 +136,7 @@ else if ($dopost == "repairAll") {
if ($rs) {
echo "修复表 {$row[0]} 完成<br>";
} else {
echo "修复表 {$row[0]} 失败,原因是: " . $dsql->GetError();
echo "修复表 {$row[0]} 失败,原因是: ".$dsql->GetError();
}
}
}
@@ -211,47 +211,20 @@ else if ($dopost == "query") {
exit();
} else if ($dopost == "docs") {
if ($cfg_dbtype == 'sqlite') {
die("SQLite 数据库不支持此功能");
die("SQLite数据库不支持此功能");
}
CheckCSRF();
$dsql->SetQuery("SHOW TABLES");
$dsql->Execute('t');
$output = '<!DOCTYPE html>
<html lang="en">
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/static/web/css/bootstrap.min.css">
<link rel="stylesheet" href="/static/web/css/admin.css">
<title>DedeBIZ数据库文档</title>
<style>
body {
background-color: #f4f6f9;
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}
.card {
border: none;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
transition: transform 0.2s ease-in-out;
}
.card:hover {
transform: translateY(-5px);
}
.card-header {
background-color: #1eb867;
color: white;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
}
.table thead th {
background-color: #e9ecef;
padding: 10px;
}
.table tbody td {
padding: 10px;
}
</style>
<style>.card{border:none;border-radius:0.5rem;box-shadow:0 4px 8px rgba(0,0,0,0.1);transition:transform 0.5s}.card:hover{transform:translateY(-0.25rem)}.card-header{background-color:#1eb867;color:white;border-top-left-radius:0.5rem!important;border-top-right-radius:0.5rem!important}.table thead th{background-color:#e9ecef;padding:0.5rem}.table tbody td{padding:0.5rem}</style>
</head>
<body>
<div class="container-fluid">
@@ -260,24 +233,22 @@ else if ($dopost == "query") {
<li class="breadcrumb-item active"><a href="sys_sql_query.php">SQL命令工具</a></li>
<li class="breadcrumb-item">数据库文档</li>
</ol>';

while ($row = $dsql->GetArray('t', MYSQL_BOTH)) {
$tableName = $row[0];
$output .= '<div class="card mb-4">
$output .= '<div class="card mb-3">
<div class="card-header">
<span>表名: ' . $tableName . '</span>
<span>表名: '.$tableName.'</span>
</div>
<div class="card-body">';
// 获取表的注释
//获取表的注释
$dsql->SetQuery("SELECT TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = '$tableName'");
$dsql->Execute('c');
$tableCommentRow = $dsql->GetArray('c', MYSQL_BOTH);
$tableComment = $tableCommentRow['TABLE_COMMENT'];
if (!empty($tableComment)) {
$output .= '<p><strong>表注释:</strong> ' . $tableComment . '</p>';
$output .= '<p><strong>表注释:</strong> '.$tableComment.'</p>';
}

// 获取表的字段信息
//获取表的字段信息
$dsql->SetQuery("SELECT COLUMN_NAME, COLUMN_TYPE, IS_NULLABLE, COLUMN_DEFAULT, COLUMN_COMMENT FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = '$tableName'");
$dsql->Execute('col');
$output .= '<table class="table table-striped table-bordered">
@@ -299,28 +270,25 @@ else if ($dopost == "query") {
$columnComment = $colRow['COLUMN_COMMENT'];

$output .= '<tr>
<td>' . $columnName . '</td>
<td>' . $columnType . '</td>
<td>' . $isNullable . '</td>
<td>' . ($columnDefault!== null? $columnDefault : '无') . '</td>
<td>' . $columnComment. '</td>
<td>'.$columnName.'</td>
<td>'.$columnType.'</td>
<td>'.$isNullable.'</td>
<td>'.($columnDefault !== null? $columnDefault : '无').'</td>
<td>'.$columnComment. '</td>
</tr>';
}
$output .= '</tbody>
</table>

</div>
</div>';
}

$output .= '</div>
<footer class="bg-light text-center py-3">
<p class="mb-0">版权所有 &copy; ' . date('Y') . ' <a href="https://www.dedebiz.com/?from=dbdocs" class="text-success">DedeBIZ</a> 保留所有权利。</p>
<p class="mb-0">版权所有 &copy; '.date('Y').' <a href="https://www.dedebiz.com/?from=dbdocs" class="text-success">DedeBIZ</a> 保留所有权利。</p>
</footer>
</body>
</html>';

// 输出 HTML 文档
//输出网页文档
header('Content-Type: text/html');
echo $output;
exit();


正在加载...
取消
保存