-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_info.php
131 lines (110 loc) · 4.09 KB
/
_info.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<!DOCTYPE html>
<html>
<head>
<title>Database Information</title>
<style>
* {
box-sizing: border-box;
}
.collapsible {
cursor: pointer;
padding: 0.3em;
width: 100%;
border: none;
text-align: left;
outline: none;
background-color: #88f;
font-size: 16px;
}
.content {
padding: 0 18px;
display: none;
overflow: hidden;
background-color: #ffffff;
}
</style>
</head>
<body>
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$servername = $_POST['servername'];
$username = $_POST['username'];
$password = $_POST['password'];
$database = $_POST['database'];
// Create a connection
$conn = new mysqli($servername, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Display databases
$sqlDatabases = "SHOW DATABASES";
$resultDatabases = $conn->query($sqlDatabases);
if ($resultDatabases->num_rows > 0) {
echo "<h2>Databases:</h2>";
echo "<ul>";
while ($row = $resultDatabases->fetch_assoc()) {
$databaseName = $row['Database'];
echo "<li class='collapsible'>$databaseName</li>";
// Display tables and columns within each database
$sqlTables = "SHOW TABLES FROM $databaseName";
$resultTables = $conn->query($sqlTables);
if ($resultTables->num_rows > 0) {
echo "<div class='content'>";
echo "<ul>";
while ($rowTable = $resultTables->fetch_assoc()) {
$tableName = $rowTable["Tables_in_$databaseName"];
echo "<li class='collapsible'>$tableName</li>";
$sqlColumns = "SHOW COLUMNS FROM $databaseName.$tableName";
$resultColumns = $conn->query($sqlColumns);
if ($resultColumns->num_rows > 0) {
echo "<div class='content'>";
echo "<ul>";
while ($rowColumn = $resultColumns->fetch_assoc()) {
$columnName = $rowColumn['Field'];
echo "<li>$columnName</li>";
}
echo "</ul>";
echo "</div>";
}
}
echo "</ul>";
echo "</div>";
}
}
echo "</ul>";
} else {
echo "No databases found.";
}
// Close the connection
$conn->close();
}
?>
<form method="POST">
<label for="servername">Server Name:</label>
<input type="text" id="servername" name="servername" value="localhost" required><br><br>
<label for="username">Username:</label>
<input type="text" id="username" name="username" value="root" required><br><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password" value=""><br><br>
<label for="database">Database Name:</label>
<input type="text" id="database" name="database" value="database00" required><br><br>
<input type="submit" name="submit" value="Connect">
</form>
<script>
var coll = document.getElementsByClassName("collapsible");
var i;
for (i = 0; i < coll.length; i++) {
coll[i].addEventListener("click", function() {
this.classList.toggle("active");
var content = this.nextElementSibling;
if (content.style.display === "block") {
content.style.display = "none";
} else {
content.style.display = "block";
}
});
}
</script>
</body>
</html>