Update api.php

This commit is contained in:
2026-06-09 07:18:33 +00:00
parent 11706d80a8
commit be292d42c7
+8 -12
View File
@@ -1,25 +1,21 @@
<?php
session_start();
error_reporting(E_ALL);
ini_set('display_errors', 1);
header("Content-Type: application/json");
// ── KONFIGURASI DATABASE INTERNAL COOLIFY ─────────────────────
$host = 'mysql-database-xwc8cwc88g4ksccsw0880848';
$port = '3306';
$db = 'default';
$user = 'mysql';
$pass = 'hKZQ51CbVYQsSQL7j5799WtF0kgqTHg4hNRgKo6fq3WSQAHHDFBz3gtIPRAMfTcO';
// ── KONFIGURASI DATABASE ──────────────────────────────────────
$host = getenv('DB_HOST') ?: $_ENV['DB_HOST'] ?: $_SERVER['DB_HOST'] ?: '127.0.0.1';
$db = getenv('DB_NAME') ?: $_ENV['DB_NAME'] ?: $_SERVER['DB_NAME'] ?: 'webgis_poverty';
$user = getenv('DB_USER') ?: $_ENV['DB_USER'] ?: $_SERVER['DB_USER'] ?: 'root';
$pass = getenv('DB_PASS') ?: $_ENV['DB_PASS'] ?: $_SERVER['DB_PASS'] ?: '';
try {
$pdo = new PDO("mysql:host=$host;port=$port;dbname=$db;charset=utf8mb4", $user, $pass, [
$pdo = new PDO("mysql:host=$host;dbname=$db;charset=utf8mb4", $user, $pass, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_TIMEOUT => 5
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
]);
} catch (PDOException $e) {
http_response_code(500);
echo json_encode(['error' => 'Gagal Konek Internal: ' . $e->getMessage()]);
echo json_encode(['error' => 'Koneksi DB Gagal: ' . $e->getMessage()]);
exit;
}