query("SET FOREIGN_KEY_CHECKS = 0;"); if ($conn->multi_query($sql)) { do { if ($res = $conn->store_result()) { $res->free(); } } while ($conn->more_results() && $conn->next_result()); $conn->query("SET FOREIGN_KEY_CHECKS = 1;"); $logs[] = "File SQL " . basename($filepath) . " berhasil diimpor sepenuhnya."; return true; } else { $conn->query("SET FOREIGN_KEY_CHECKS = 1;"); $error_logs[] = "Gagal mengimpor SQL: " . $conn->error; return false; } } // Handler Aksi Perbaikan Database (Hanya berjalan jika terautentikasi) $action_result = null; if ($authenticated && isset($_POST['action'])) { $action = $_POST['action']; if ($action === 'check_connection') { if ($conn->ping()) { $logs[] = "Koneksi ke database server aktif! Server info: " . $conn->server_info; } else { $error_logs[] = "Koneksi database terputus: " . $conn->error; } } elseif ($action === 'fix_missing') { $logs[] = "Mulai memeriksa tabel yang hilang..."; // Dapatkan DDL Cadangan $sql_file = __DIR__ . '/../database.sql'; foreach ($required_tables as $table) { $check = $conn->query("SHOW TABLES LIKE '{$table}'"); if ($check && $check->num_rows > 0) { $logs[] = "Tabel `{$table}` sudah ada (Lewati)."; } else { $logs[] = "Tabel `{$table}` hilang! Mencoba membuat tabel..."; // Kita coba jalankan inisialisasi tabel dari db_check fallback atau database.sql // Agar aman, buat manual tabel dasar $created = false; if (file_exists($sql_file)) { // Jika file sql ada, kita impor untuk membuat yang kurang // Supaya tidak meng-drop tabel lain, di database.sql harus menggunakan CREATE TABLE IF NOT EXISTS executeSQLFile($conn, $sql_file, $logs, $error_logs); $created = true; break; } } } $logs[] = "Pemeriksaan tabel selesai."; } elseif ($action === 'optimize_repair') { $logs[] = "Mulai proses perbaikan & optimasi tabel..."; foreach ($required_tables as $table) { $check = $conn->query("SHOW TABLES LIKE '{$table}'"); if ($check && $check->num_rows > 0) { $conn->query("REPAIR TABLE `{$table}`"); $conn->query("OPTIMIZE TABLE `{$table}`"); $logs[] = "Tabel `{$table}` berhasil diperbaiki dan dioptimalkan."; } else { $error_logs[] = "Tabel `{$table}` tidak ditemukan untuk dioptimalkan."; } } $logs[] = "Proses optimasi selesai."; } elseif ($action === 'hard_reset') { $logs[] = "⚠️ Melakukan HARD RESET Database..."; // Drop all known tables $conn->query("SET FOREIGN_KEY_CHECKS = 0;"); foreach ($required_tables as $table) { $conn->query("DROP TABLE IF EXISTS `{$table}`"); $logs[] = "Menghapus tabel `{$table}` jika ada."; } $conn->query("SET FOREIGN_KEY_CHECKS = 1;"); // Impor ulang database.sql $sql_file = __DIR__ . '/../database.sql'; if (executeSQLFile($conn, $sql_file, $logs, $error_logs)) { $logs[] = "✅ Database berhasil di-reset ke kondisi awal."; } else { $error_logs[] = "❌ Hard reset gagal saat mengimpor skema."; } } } // Kumpulkan status database saat ini $status_tables = []; if ($authenticated && !$conn->connect_error) { foreach ($required_tables as $table) { $check = $conn->query("SHOW TABLES LIKE '{$table}'"); if ($check && $check->num_rows > 0) { $count_res = $conn->query("SELECT COUNT(*) as total FROM `{$table}`"); $count = $count_res ? $count_res->fetch_assoc()['total'] : 0; $status_tables[$table] = [ 'exists' => true, 'count' => $count ]; } else { $status_tables[$table] = [ 'exists' => false, 'count' => 0 ]; } } } ?> Database Master Tool - WebGIS

🛠️ Database Master Debug Tool Logout / Lock

Keamanan Diperlukan

Masukkan PIN Keamanan untuk mengakses fungsi diagnostik database.

* PIN default lokal adalah 123456 (Atur via DB_TOOL_PIN di .env)

📊 Status Tabel Database

false, 'count' => 0]; ?>
Nama Tabel Keberadaan Jumlah Data
OK (Tersedia) Hilang / Tidak Ada Baris

⚡ Aksi Perbaikan

Konektivitas Database Uji ulang ping ke server MySQL dan baca info status server.
Buat Tabel yang Hilang Membuat tabel yang hilang secara otomatis tanpa menyentuh tabel yang sudah ada.
Perbaiki & Optimasi Menjalankan perintah SQL REPAIR dan OPTIMIZE untuk memperbaiki data corrupt.
Reset Ulang (Hard Reset) Menghapus semua tabel dan mengimpor ulang skema awal dari database.sql.

💻 Output Log Eksekusi

[INFO]
[ERROR]
← Kembali ke Portal WebGIS