<?php
// config/database.php

if (isset($_SERVER['SCRIPT_NAME'])) {
    define('BASE_URL', rtrim(dirname($_SERVER['SCRIPT_NAME']), '/'));
} else {
    define('BASE_URL', BASE_URL);
}

define('DB_HOST', 'localhost');
define('DB_USER', 'PUT_YOUR_CPANEL_DB_USERNAME_HERE');
define('DB_PASS', 'PUT_YOUR_CPANEL_DB_PASSWORD_HERE');
define('DB_NAME', 'PUT_YOUR_CPANEL_DB_NAME_HERE');

function getDB() {
    static $pdo = null;
    if ($pdo === null) {
        try {
            $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,
            ];
            $pdo = new PDO($dsn, DB_USER, DB_PASS, $options);
        } catch (\PDOException $e) {
            throw new \PDOException($e->getMessage(), (int)$e->getCode());
        }
    }
    return $pdo;
}

