<?php
// Database configuration
$host     = "localhost";          // Database host
$db_name  = "kkfxoaad_bella";     // Database name
$db_user  = "kkfxoaad";           // Database username
$db_pass  = "Bitok@2025";         // Database password
$charset  = "utf8mb4";

// --------------------
// Main PDO connection
// --------------------
try {
    $dsn = "mysql:host=$host;dbname=$db_name;charset=$charset";
    $options = [
        PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION, // Throw exceptions on errors
        PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,       // Fetch assoc arrays
        PDO::ATTR_EMULATE_PREPARES   => false,                  // Use native prepared statements
    ];

    $conn = new PDO($dsn, $db_user, $db_pass, $options);

} catch (PDOException $e) {
    // If PDO connection fails → stop execution safely
    die("❌ Database connection failed (PDO): " . htmlspecialchars($e->getMessage()));
}

// ----------------------------
// Optional MySQLi connection
// ----------------------------
// Only needed if you still use mysqli_* in some old pages.
// If not, you can safely delete this entire section.
$mysqli = @new mysqli($host, $db_user, $db_pass, $db_name);

if ($mysqli && $mysqli->connect_errno) {
    // Log error but don't kill the app
    error_log("MySQLi connection failed: " . $mysqli->connect_error);
    $mysqli = null; // Disable mysqli if broken
}
?>
