基于PHP简易版MySQL可视化脚本

mysql_manager.php

上传脚本到服务器即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<!DOCTYPE html>
<html>
<head>
<title>执行MySQL语句</title>
</head>
<body>
<h1>执行MySQL语句</h1>
<form method="POST" action="">
<textarea name="sql_statement" rows="5" cols="50" placeholder="请输入MySQL语句"></textarea>
<br>
<input type="submit" value="执行">
</form>
<?php
// 检查是否提交了表单
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// 获取用户输入的MySQL语句
$sql_statement = $_POST['sql_statement'];
// 连接MySQL数据库
$host = 'localhost';
$username = 'root';
$password = '123456';
$database = 'mysql';
$connection = mysqli_connect($host, $username, $password, $database);
// 执行MySQL查询
$result = mysqli_query($connection, $sql_statement);
// 检查查询结果
if ($result) {
// 回显查询结果
echo '<h2>查询结果:</h2>';
while ($row = mysqli_fetch_assoc($result)) {
echo '<pre>';
print_r($row);
echo '</pre>';
}
} else {
// 显示错误消息
echo '<h2>错误:</h2>';
echo '<p>' . mysqli_error($connection) . '</p>';
}
// 关闭数据库连接
mysqli_close($connection);
}
?>
</body>
</html>

使用时,修改如下参数

image-20231016005053345

使用案例

image-20231016005127255