<?php
define('ENVIRONMENT', 'development');

define('DB_HOST', 'localhost');
define('DB_NAME', 'aseshopm_baltic_trader');
define('DB_USER', 'aseshopm_baltic_trader_user');
define('DB_PASS', '@Sarobidy1998');

ini_set('log_errors', 'On');
ini_set('error_log', __DIR__ . '/../logs/php_errors.log');
error_reporting(E_ALL);

function getDbConnection() {
    try {
        $pdo = new PDO(
            "mysql:host=" . DB_HOST . ";dbname=" . DB_NAME . ";charset=utf8mb4",
            DB_USER,
            DB_PASS,
            [
                PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
                PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
                PDO::ATTR_EMULATE_PREPARES   => false
            ]
        );
        return $pdo;
    } catch (PDOException $e) {
        error_log("DB Connection Error: " . $e->getMessage());
        if (ENVIRONMENT === 'development') {
            die("Erreur DB : " . $e->getMessage());
        } else {
            die("Erreur interne, réessayez plus tard.");
        }
    }
}

// BasePath fixe (chemin depuis la racine du serveur web)
$basePath = '/baltic_trader/public';
