<?php
// api/db_connect.php

$host = 'localhost';
$db   = 'perg2211_permataibu'; // <--- UBAH DI SINI
$user = 'perg2211_user';
$pass = 'Pkmkraksaan1*';
$charset = 'utf8mb4';

$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
$options = [
    PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
    PDO::ATTR_EMULATE_PREPARES   => false,
];

try {
    $pdo = new PDO($dsn, $user, $pass, $options);
} catch (\PDOException $e) {
    http_response_code(500);
    echo json_encode(['success' => false, 'message' => 'Koneksi database gagal: ' . $e->getMessage()]); // Tambahkan $e->getMessage() untuk debugging awal
    exit();
}
?>