<?php
/**
 * Database connection settings.
 * EDIT THESE FOUR LINES with your real MySQL credentials before going live.
 * On cPanel, the database name and username are usually prefixed with your
 * cPanel username, e.g. "cpaneluser_pims_nepal".
 */
define('DB_HOST', 'localhost');
define('DB_NAME', 'skhata_pimsnepal');
define('DB_USER', 'skhata_pimsnepal');
define('DB_PASS', 'pimsnepal@123');

/**
 * Base URL of the site (no trailing slash). Used to build absolute links
 * for SEO tags and uploaded file URLs. Leave blank to auto-detect.
 */
define('SITE_URL', '');

function db(): PDO
{
    static $pdo = null;
    if ($pdo === null) {
        $dsn = 'mysql:host=' . DB_HOST . ';dbname=' . DB_NAME . ';charset=utf8mb4';
        $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, DB_USER, DB_PASS, $options);
        } catch (PDOException $e) {
            http_response_code(500);
            die('Database connection failed. Please check config/database.php with your real MySQL credentials. (' . htmlspecialchars($e->getMessage()) . ')');
        }
    }
    return $pdo;
}
