prepare(" INSERT INTO jalan (nama_jalan, status, panjang, geojson) VALUES (?, ?, ?, ?) "); $total = 0; $success = 0; $failed = 0; foreach ($data['features'] as $feature) { $total++; // Ambil data dari properties $nama = $feature['properties']['nama_jalan'] ?? 'Tanpa Nama'; $status = $feature['properties']['status_jal'] ?? 'Kabupaten'; $panjang = $feature['properties']['Plan_Len'] ?? 0; // Validasi status (biar sesuai ENUM DB) $allowed_status = ['Nasional', 'Provinsi', 'Kabupaten', 'Kota']; if (!in_array($status, $allowed_status)) { $status = 'Kabupaten'; } // Ambil koordinat if (!isset($feature['geometry']['coordinates'])) { $failed++; continue; } $coordinates = $feature['geometry']['coordinates']; // Convert dari [lng, lat] → [lat, lng] $geo = []; foreach ($coordinates as $coord) { if (count($coord) < 2) continue; $geo[] = [$coord[1], $coord[0]]; } if (count($geo) < 2) { $failed++; continue; } $geojson = json_encode($geo); // Bind & execute $stmt->bind_param("ssds", $nama, $status, $panjang, $geojson); if ($stmt->execute()) { $success++; } else { $failed++; } } $stmt->close(); $conn->close(); // Output hasil echo "

✅ Import Selesai

"; echo "Total data: $total
"; echo "Berhasil: $success
"; echo "Gagal: $failed
"; ?>