<?php
/**
 * koneksi.php
 */

$config = require __DIR__ . '/config.php'; // ⬅️ PAKAI require BIASA

$db = $config['db'];

$conn = new mysqli(
    $db['host'],
    $db['user'],
    $db['pass'],
    $db['name']
);

if ($conn->connect_error) {
    error_log(
        date('[Y-m-d H:i:s] ') .
        'DB ERROR: ' . $conn->connect_error . PHP_EOL,
        3,
        __DIR__ . '/log_error.txt'
    );

    http_response_code(500);
    exit(json_encode([
        'status' => 'error',
        'message' => 'Database connection failed'
    ]));
}

$conn->set_charset('utf8mb4');
