<?php
// Database Configuration
$host = "localhost";
$dbname = "expenses_management";
$username = "root";
$password = ""; // Add your MySQL password here

try {

    $pdo = new PDO(
        "mysql:host=$host;dbname=$dbname;charset=utf8mb4",
        $username,
        $password
    );

    // Enable PDO error mode
    $pdo->setAttribute(
        PDO::ATTR_ERRMODE,
        PDO::ERRMODE_EXCEPTION
    );

    // Default fetch mode
    $pdo->setAttribute(
        PDO::ATTR_DEFAULT_FETCH_MODE,
        PDO::FETCH_ASSOC
    );

    // Disable emulated prepares for better security
    $pdo->setAttribute(
        PDO::ATTR_EMULATE_PREPARES,
        false
    );


} catch(PDOException $e) {

    die("
    <div style='
        background:#fee2e2;
        color:#991b1b;
        padding:20px;
        margin:50px;
        border-radius:10px;
        font-family:Arial;
        text-align:center;
    '>

    <h2>Database Connection Failed</h2>

    <p>".$e->getMessage()."</p>

    </div>
    ");

}
?>