-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathget_schema.php
More file actions
52 lines (47 loc) · 1.53 KB
/
get_schema.php
File metadata and controls
52 lines (47 loc) · 1.53 KB
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
<?php
include 'db_connect.php';
echo "<h2>Current Database Schema</h2>";
// Get all tables
$tables = $conn->query("SHOW TABLES");
while($table = $tables->fetch_array()) {
$tableName = $table[0];
echo "<h3>Table: $tableName</h3>";
// Get table structure
$structure = $conn->query("DESCRIBE $tableName");
echo "<table border='1'>";
echo "<tr><th>Field</th><th>Type</th><th>Null</th><th>Key</th><th>Default</th><th>Extra</th></tr>";
while($row = $structure->fetch_assoc()) {
echo "<tr>";
echo "<td>{$row['Field']}</td>";
echo "<td>{$row['Type']}</td>";
echo "<td>{$row['Null']}</td>";
echo "<td>{$row['Key']}</td>";
echo "<td>{$row['Default']}</td>";
echo "<td>{$row['Extra']}</td>";
echo "</tr>";
}
echo "</table><br>";
// Show sample data
$sample = $conn->query("SELECT * FROM $tableName LIMIT 3");
if($sample->num_rows > 0) {
echo "<strong>Sample Data:</strong><br>";
echo "<table border='1'>";
$fields = $sample->fetch_fields();
echo "<tr>";
foreach($fields as $field) {
echo "<th>{$field->name}</th>";
}
echo "</tr>";
$sample = $conn->query("SELECT * FROM $tableName LIMIT 3");
while($row = $sample->fetch_assoc()) {
echo "<tr>";
foreach($row as $value) {
echo "<td>" . htmlspecialchars($value) . "</td>";
}
echo "</tr>";
}
echo "</table>";
}
echo "<hr>";
}
?>