34 lines
1.1 KiB
PHP
34 lines
1.1 KiB
PHP
<?php
|
|
// ============================================================
|
|
// KONFIGURASI DATABASE
|
|
// File: config.php
|
|
// ============================================================
|
|
|
|
define('DB_HOST', 'localhost');
|
|
define('DB_USER', 'root'); // Sesuaikan dengan user MySQL Anda
|
|
define('DB_PASS', ''); // Sesuaikan dengan password MySQL Anda
|
|
define('DB_NAME', 'webgis_p3');
|
|
|
|
function getDB() {
|
|
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
|
|
if ($conn->connect_error) {
|
|
http_response_code(500);
|
|
die(json_encode(['error' => 'Koneksi database gagal: ' . $conn->connect_error]));
|
|
}
|
|
$conn->set_charset('utf8mb4');
|
|
return $conn;
|
|
}
|
|
|
|
// Header CORS & JSON untuk semua response
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
header('Access-Control-Allow-Origin: *');
|
|
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
|
|
header('Access-Control-Allow-Headers: Content-Type');
|
|
|
|
// Handle preflight OPTIONS request
|
|
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
|
|
http_response_code(200);
|
|
exit();
|
|
}
|
|
?>
|