fix : bug

This commit is contained in:
2026-06-11 20:48:27 +07:00
parent 84305e34ff
commit 33c28ec0d4
4 changed files with 125 additions and 7 deletions
+6 -5
View File
@@ -3,16 +3,17 @@
// config/db.php — Database connection (PDO)
// ============================================================
define('DB_HOST', '127.0.0.1'); // ← ganti dari localhost ke 127.0.0.1
define('DB_NAME', 'webgis_db'); // ← ganti dari webgis_db ke webgis
define('DB_USER', 'root');
define('DB_PASS', 'root123');
define('DB_HOST', 'vsw0wwo480kg8sooc0s00sow');
define('DB_PORT', '3306');
define('DB_NAME', 'Pemetaan_Kemiskinan');
define('DB_USER', 'mysql');
define('DB_PASS', '4ZUbGM9LD8zcJuGz0xgGOvNkLrAtZiarqP0QSCrM6uYM5ZHGuMVm1xXu68ChfyRa');
define('DB_CHARSET', 'utf8mb4');
function getDB(): PDO {
static $pdo = null;
if ($pdo === null) {
$dsn = sprintf('mysql:host=%s;dbname=%s;charset=%s', DB_HOST, DB_NAME, DB_CHARSET);
$dsn = sprintf('mysql:host=%s;port=%s;dbname=%s;charset=%s', DB_HOST, DB_PORT, DB_NAME, DB_CHARSET);
$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
+2 -2
View File
@@ -4,8 +4,8 @@
-- Lines (Roads), Polygons (Land Parcels)
-- ============================================================
CREATE DATABASE IF NOT EXISTS webgis_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
USE webgis_db;
-- CREATE DATABASE IF NOT EXISTS webgis_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- USE webgis_db;
-- ------------------------------------------------------------
-- TABLE: points
+80
View File
@@ -0,0 +1,80 @@
<?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>";
+37
View File
@@ -0,0 +1,37 @@
<?php
require_once __DIR__ . '/config/db.php';
echo "<h1>Import Database</h1>";
$sqlFile = __DIR__ . '/database/database.sql';
if (!file_exists($sqlFile)) {
die("Error: File database.sql tidak ditemukan di path: " . htmlspecialchars($sqlFile));
}
$sql = file_get_contents($sqlFile);
if (empty(trim($sql))) {
die("Error: File database.sql kosong.");
}
try {
$pdo = getDB();
// Nonaktifkan foreign key checks untuk menghindari error saat drop/create tabel
$pdo->exec("SET FOREIGN_KEY_CHECKS = 0;");
// Eksekusi semua query yang ada di dalam file SQL
$pdo->exec($sql);
// Aktifkan kembali foreign key checks
$pdo->exec("SET FOREIGN_KEY_CHECKS = 1;");
echo "<h3 style='color: green;'>Import Berhasil!</h3>";
echo "<p>Seluruh struktur tabel dan data dari file database.sql telah berhasil dieksekusi ke database <b>" . htmlspecialchars(DB_NAME) . "</b>.</p>";
echo "<p><a href='debug.php'>Lihat isi database di sini (debug.php)</a></p>";
} catch (PDOException $e) {
echo "<h3 style='color: red;'>Import Gagal!</h3>";
echo "<p><b>Error Message:</b> " . htmlspecialchars($e->getMessage()) . "</p>";
}