27 lines
836 B
PHP
27 lines
836 B
PHP
<?php
|
|
// config.php - Konfigurasi Database
|
|
define('DB_HOST', getenv('DB_HOST') ?: 'localhost');
|
|
define('DB_USER', getenv('DB_USER') ?: 'root');
|
|
define('DB_PASS', getenv('DB_PASS') ?: '');
|
|
define('DB_NAME', getenv('DB_NAME') ?: 'polyline_polygon');
|
|
|
|
function getDB() {
|
|
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
|
|
if ($conn->connect_error) {
|
|
die(json_encode(['success' => false, 'message' => 'Koneksi database gagal: ' . $conn->connect_error]));
|
|
}
|
|
$conn->set_charset('utf8mb4');
|
|
return $conn;
|
|
}
|
|
|
|
// Set header untuk API
|
|
header('Content-Type: application/json');
|
|
header('Access-Control-Allow-Origin: *');
|
|
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
|
|
header('Access-Control-Allow-Headers: Content-Type');
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
|
|
exit(0);
|
|
}
|
|
?>
|