<?php
/**
 * Database connection config.
 * Update these four constants to match your hosting environment.
 */
define('DB_HOST', 'localhost');
define('DB_NAME', 'skhata_excellentedu');
define('DB_USER', 'skhata_excellentedu');
define('DB_PASS', 'excellentedu@123');

/** Base URL of the site (no trailing slash), used for sitemap/canonical/OG tags. */
define('SITE_URL', 'https://excellenteducation.com.np/');

function db(): PDO {
    static $pdo = null;
    if ($pdo === null) {
        $dsn = 'mysql:host=' . DB_HOST . ';dbname=' . DB_NAME . ';charset=utf8mb4';
        try {
            $pdo = new PDO($dsn, DB_USER, DB_PASS, [
                PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
                PDO::ATTR_DEFAULT_FETCH_MODE  => PDO::FETCH_ASSOC,
                PDO::ATTR_EMULATE_PREPARES    => false,
            ]);
        } catch (PDOException $e) {
            http_response_code(500);
            die('Database connection failed. Please check config/db.php and ensure the "excellent_education" database has been imported from database/schema.sql. (' . htmlspecialchars($e->getMessage()) . ')');
        }
    }
    return $pdo;
}
