<?php
$basePath = dirname(dirname(__FILE__)). '/';//$basePath = __DIR__ . '/';
define("BASE_PATH", $basePath);
require_once BASE_PATH . "vendor/autoload.php";

$dotenv = Dotenv\Dotenv::createImmutable(BASE_PATH);
$dotenv->load();

foreach ($_ENV as $key => $value) {
    putenv("$key=$value");
}


define("BASE_URL", getenv("BASE_URL"));


$host = getenv("DB_HOST");
$user = getenv("DB_USER");
$pass = getenv("DB_PASS");
$dbname = getenv("DB_NAME");

try {
    // Create a new PDO instance
    $dsn = "mysql:host=$host;dbname=$dbname";
    $conn = new PDO($dsn, $user, $pass);

    // Set PDO attributes to handle errors properly
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    // echo "Connection successful!";
} catch (PDOException $e) {
    // Catch any errors during the connection and display the message
    echo "Connection failed: " . $e->getMessage();
    die();
}

require_once $basePath . 'helpers/common.php';
require_once $basePath . 'helpers/web.php';
