81 lines
3.0 KiB
PHP
81 lines
3.0 KiB
PHP
<?php
|
|
require_once __DIR__ . '/config/db.php';
|
|
|
|
echo "<html><head><title>Database Debugger</title>";
|
|
echo "<style>
|
|
body { font-family: sans-serif; margin: 20px; }
|
|
table { border-collapse: collapse; width: 100%; margin-bottom: 30px; font-size: 14px; }
|
|
th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
|
|
th { background-color: #f4f4f4; }
|
|
tr:nth-child(even) { background-color: #fafafa; }
|
|
h2 { border-bottom: 2px solid #ccc; padding-bottom: 5px; }
|
|
.alert { padding: 15px; background-color: #f44336; color: white; margin-bottom: 15px; }
|
|
</style>";
|
|
echo "</head><body>";
|
|
|
|
echo "<h1>🔍 Database Debugger</h1>";
|
|
|
|
try {
|
|
$pdo = getDB();
|
|
|
|
echo "<p>Koneksi ke database <b>" . htmlspecialchars(DB_NAME) . "</b> berhasil.</p>";
|
|
|
|
// Ambil daftar semua tabel
|
|
$stmt = $pdo->query("SHOW TABLES");
|
|
$tables = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
|
|
|
if (empty($tables)) {
|
|
echo "<p>Tidak ada tabel yang ditemukan di database ini. Pastikan Anda sudah melakukan <a href='import.php'>import database</a>.</p>";
|
|
} else {
|
|
echo "<p>Ditemukan " . count($tables) . " tabel.</p>";
|
|
|
|
foreach ($tables as $table) {
|
|
echo "<h2>Tabel: " . htmlspecialchars($table) . "</h2>";
|
|
|
|
// Ambil struktur tabel (kolom)
|
|
$stmtCols = $pdo->query("SHOW COLUMNS FROM `" . $table . "`");
|
|
$columns = $stmtCols->fetchAll(PDO::FETCH_COLUMN);
|
|
|
|
// Ambil data (limit 100 baris agar tidak berat jika datanya sangat banyak)
|
|
$stmtData = $pdo->query("SELECT * FROM `" . $table . "` LIMIT 100");
|
|
$rows = $stmtData->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
if (empty($rows)) {
|
|
echo "<p><i>Tabel ini tidak memiliki data (kosong).</i></p>";
|
|
} else {
|
|
echo "<table>";
|
|
echo "<tr>";
|
|
foreach ($columns as $col) {
|
|
echo "<th>" . htmlspecialchars($col) . "</th>";
|
|
}
|
|
echo "</tr>";
|
|
|
|
foreach ($rows as $row) {
|
|
echo "<tr>";
|
|
foreach ($columns as $col) {
|
|
$val = $row[$col];
|
|
// Batasi panjang teks yang sangat panjang (misal multipolygon/geojson) untuk debug
|
|
if (is_string($val) && strlen($val) > 100) {
|
|
$val = substr($val, 0, 100) . "... [terpotong]";
|
|
}
|
|
echo "<td>" . htmlspecialchars((string)$val) . "</td>";
|
|
}
|
|
echo "</tr>";
|
|
}
|
|
echo "</table>";
|
|
|
|
if (count($rows) == 100) {
|
|
echo "<p><i>* Hanya menampilkan 100 baris pertama.</i></p>";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} catch (PDOException $e) {
|
|
echo "<div class='alert'>";
|
|
echo "<strong>Error Koneksi Database:</strong><br>";
|
|
echo htmlspecialchars($e->getMessage());
|
|
echo "</div>";
|
|
}
|
|
|
|
echo "</body></html>";
|