119 lines
7.5 KiB
PHP
119 lines
7.5 KiB
PHP
<?php
|
|
// ====================================================================
|
|
// 1. KONFIGURASI DATABASE (Silakan sesuaikan nama DB jika berbeda)
|
|
// ====================================================================
|
|
$host = "localhost";
|
|
$user = "root";
|
|
$pass = "";
|
|
$db = "tugas_akhir_webgis"; // Mengikuti nama folder htdocs Anda
|
|
|
|
$koneksi = new mysqli($host, $user, $pass, $db);
|
|
if ($koneksi->connect_error) {
|
|
die("Koneksi Gagal: " . $koneksi->connect_error);
|
|
}
|
|
|
|
echo "<h2>⚙️ Menjalankan Smart-Infus Data Spasial EcoGIS...</h2>";
|
|
|
|
// ====================================================================
|
|
// 2. DETEKSI NAMA TABEL SECARA OTOMATIS (Anti-Eror Nama Tabel)
|
|
// ====================================================================
|
|
$daftar_tabel_db = [];
|
|
$ambil_tabel = $koneksi->query("SHOW TABLES");
|
|
while($row = $ambil_tabel->fetch_row()) {
|
|
$daftar_tabel_db[] = strtolower($row[0]);
|
|
}
|
|
|
|
// Deteksi tabel ibadah/posko
|
|
$tabel_ibadah = "";
|
|
foreach($daftar_tabel_db as $t) {
|
|
if(strpos($t, 'ibadah') !== false || strpos($t, 'posko') !== false || strpos($t, 'masjid') !== false) {
|
|
$tabel_ibadah = $t;
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Deteksi tabel warga/kemiskinan
|
|
$tabel_warga = "";
|
|
foreach($daftar_tabel_db as $t) {
|
|
if(strpos($t, 'warga') !== false || strpos($t, 'miskin') !== false || strpos($t, 'poverty') !== false || strpos($t, 'kk') !== false) {
|
|
$tabel_warga = $t;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if(!$tabel_ibadah || !$tabel_warga) {
|
|
die("❌ <b>Gagal Mendeteksi Tabel:</b> Sistem tidak menemukan tabel dengan nama mengandung unsur 'ibadah' atau 'warga'. Silakan periksa phpMyAdmin Anda.");
|
|
}
|
|
|
|
echo "📍 Tabel Ibadah terdeteksi: <code>$tabel_ibadah</code><br>";
|
|
echo "🏠 Tabel Warga terdeteksi: <code>$tabel_warga</code><br><hr>";
|
|
|
|
// ====================================================================
|
|
// 3. DETEKSI STRUKTUR KOLOM MASING-MASING TABEL
|
|
// ====================================================================
|
|
$kolom_ibadah = [];
|
|
$res_ib = $koneksi->query("SHOW COLUMNS FROM `$tabel_ibadah`");
|
|
while($r = $res_ib->fetch_assoc()) { $kolom_ibadah[] = $r['Field']; }
|
|
|
|
$kolom_warga = [];
|
|
$res_wg = $koneksi->query("SHOW COLUMNS FROM `$tabel_warga`");
|
|
while($r = $res_wg->fetch_assoc()) { $kolom_warga[] = $r['Field']; }
|
|
|
|
// ====================================================================
|
|
// 4. DATASET LOKASI KOTA PONTIANAK (18 DATA)
|
|
// ====================================================================
|
|
$data_ibadah = [
|
|
['Masjid Raya Mujahidin', 'Masjid', -0.032306, 109.337772],
|
|
['Gereja Katedral Santo Yoseph', 'Gereja', -0.029053, 109.336444],
|
|
['Vihara Bodhisatva Karaniya Metta', 'Vihara', -0.022221, 109.341142],
|
|
['Masjid Jami Sultan Syarif Abdurrahman', 'Masjid', -0.027221, 109.351234],
|
|
['Pura Giripati Mulawarman', 'Pura', -0.048712, 109.355112],
|
|
['Gereja PPIB Jemaat Kalimantan', 'Gereja', -0.038112, 109.321451]
|
|
];
|
|
|
|
$data_warga = [
|
|
['Keluarga Pak Budi Santoso', 'Miskin Ekstrem', 45.50, 'Program Bedah Rumah Swadaya & BPNT Prioritas', '{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[109.3101, -0.0152],[109.3102, -0.0152],[109.3102, -0.0153],[109.3101, -0.0153],[109.3101, -0.0152]]]}}'],
|
|
['Keluarga Ibu Aminah', 'Miskin', 52.10, 'Bantuan Modal Usaha UMKM & Kartu Indonesia Sehat', '{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[109.3115, -0.0165],[109.3116, -0.0165],[109.3116, -0.0166],[109.3115, -0.0166],[109.3115, -0.0165]]]}}'],
|
|
['Keluarga Syarif Usman', 'Miskin Ekstrem', 38.25, 'Restorasi Rumah Panggung Tepian Sungai & PKH', '{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[109.3555, -0.0261],[109.3556, -0.0261],[109.3556, -0.0262],[109.3555, -0.0262],[109.3555, -0.0261]]]}}'],
|
|
['Keluarga Pak Junaidi', 'Rentan', 65.00, 'Beasiswa Anak Sekolah & Pelatihan Kerja Teknis', '{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[109.3570, -0.0280],[109.3571, -0.0280],[109.3571, -0.0281],[109.3570, -0.0281],[109.3570, -0.0280]]]}}'],
|
|
['Keluarga Pak Suprianto', 'Miskin Ekstrem', 42.00, 'Pemasangan Listrik Gratis & Bantuan Sembako Reguler', '{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[109.3245, -0.0412],[109.3246, -0.0412],[109.3246, -0.0413],[109.3245, -0.0413],[109.3245, -0.0412]]]}}'],
|
|
['Keluarga Ibu Fatimah', 'Miskin', 48.75, 'Bantuan Pangan Non-Tunai (BPNT) & Subsidi Air Bersih', '{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[109.3260, -0.0425],[109.3261, -0.0425],[109.3261, -0.0426],[109.3260, -0.0426],[109.3260, -0.0425]]]}}'],
|
|
['Keluarga Ahian', 'Miskin Ekstrem', 35.40, 'Perbaikan Atap Bocor & Subsidi Beras Sejahtera', '{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[109.3450, -0.0080],[109.3451, -0.0080],[109.3451, -0.0081],[109.3450, -0.0081],[109.3450, -0.0080]]]}}'],
|
|
['Keluarga Pak Ruslan', 'Rentan', 72.30, 'Insentif Nelayan Kecil & Kartu Indonesia Pintar (KIP)', '{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[109.3475, -0.0095],[109.3476, -0.0095],[109.3476, -0.0096],[109.3475, -0.0096],[109.3475, -0.0095]]]}}'],
|
|
['Keluarga Pak Iwan Kurniawan', 'Miskin', 50.00, 'Skema Padat Karya Tunai Kelurahan & PKH', '{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[109.3620, -0.0490],[109.3621, -0.0490],[109.3621, -0.0491],[109.3620, -0.0491],[109.3620, -0.0490]]]}}'],
|
|
['Keluarga Ibu Ratna', 'Rentan', 58.90, 'Bantuan Modal Sembako warung kecil', '{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[109.3640, -0.0510],[109.3641, -0.0510],[109.3641, -0.0511],[109.3640, -0.0511],[109.3640, -0.0510]]]}}'],
|
|
['Keluarga Pak Zulkifli', 'Miskin Ekstrem', 40.10, 'Bantuan Sanitasi MCK Sehat & Bedah Rumah', '{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[109.3310, -0.0220],[109.3311, -0.0220],[109.3311, -0.0221],[109.3310, -0.0221],[109.3310, -0.0220]]]}}'],
|
|
['Keluarga Ibu Sri Wahyuni', 'Miskin', 46.80, 'Subsidi Gas 3KG & Pendampingan PKH Perempuan Mandiri', '{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[109.3325, -0.0240],[109.3326, -0.0240],[109.3326, -0.0241],[109.3325, -0.0241],[109.3325, -0.0240]]]}}']
|
|
];
|
|
|
|
// ====================================================================
|
|
// 5. EKSEKUSI PENYUNTIKAN DATA SECARA AMAN (MENGABAIKAN ID AUTO_INCREMENT)
|
|
// ====================================================================
|
|
|
|
// Suntik Data Ibadah
|
|
$c_ibadah = $kolom_ibadah; if(strtolower($c_ibadah[0]) == 'id') array_shift($c_ibadah);
|
|
$sql_ib = "INSERT INTO `$tabel_ibadah` (`".implode("`,`", $c_ibadah)."`) VALUES (?, ?, ?, ?)";
|
|
$stmt_ib = $koneksi->prepare($sql_ib);
|
|
|
|
foreach ($data_ibadah as $ib) {
|
|
$stmt_ib->bind_param("ssdd", $ib[0], $ib[1], $ib[2], $ib[3]);
|
|
$stmt_ib->execute();
|
|
}
|
|
echo "✅ <b>6 Data Titik Lokasi Rumah Ibadah</b> sukses dimasukkan!<br>";
|
|
|
|
// Suntik Data Warga
|
|
$c_warga = $kolom_warga; if(strtolower($c_warga[0]) == 'id') array_shift($c_warga);
|
|
$sql_wg = "INSERT INTO `$tabel_warga` (`".implode("`,`", $c_warga)."`) VALUES (?, ?, ?, ?, ?)";
|
|
$stmt_wg = $koneksi->prepare($sql_wg);
|
|
|
|
foreach ($data_warga as $w) {
|
|
$stmt_wg->bind_param("ssdss", $w[0], $w[1], $w[2], $w[3], $w[4]);
|
|
$stmt_wg->execute();
|
|
}
|
|
echo "✅ <b>12 Data Poligon Kavling Rumah Warga</b> sukses dimasukkan!<br><br>";
|
|
|
|
echo "🎉 <b>SUNTIK DATA BERHASIL!</b> Total 18 data spasial Kota Pontianak telah masuk ke database Anda.<br>";
|
|
echo "Silakan kembali ke halaman <b>index.php</b> lalu refresh browser Anda untuk melihat hasilnya.";
|
|
|
|
$koneksi->close();
|
|
?>
|