34 lines
1.1 KiB
PHP
34 lines
1.1 KiB
PHP
<?php
|
|
// ============================================================
|
|
// KONFIGURASI DATABASE
|
|
// File: config.php
|
|
// ============================================================
|
|
|
|
define('DB_HOST', getenv('DB_HOST') ?: 'localhost');
|
|
define('DB_USER', getenv('DB_USER') ?: 'root');
|
|
define('DB_PASS', getenv('DB_PASS') !== false ? getenv('DB_PASS') : '');
|
|
define('DB_NAME', getenv('POVERTY_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();
|
|
}
|
|
?>
|