<?php
if (session_status() == PHP_SESSION_NONE) {
    session_start();
}

/* Database credentials - handles both local and online hosting */
if ($_SERVER['HTTP_HOST'] === 'localhost' || $_SERVER['REMOTE_ADDR'] === '127.0.0.1' || $_SERVER['REMOTE_ADDR'] === '::1') {
    // Local Environment (Ampps/XAMPP)
    $host = 'localhost';
    $dbname = 'cargo';
    $db_user = 'root';
    $db_pass = 'mysql';
} else {
    // Production Online Environment (Modify these with your live server details)
    $host = 'localhost';
    $dbname = 'globala2_demo360';
    $db_user = 'globala2_demo360';
    $db_pass = 'globala2_demo360';
}

define('DB_SERVER', $host);
define('DB_USERNAME', $db_user);
define('DB_PASSWORD', $db_pass);
define('DB_NAME', $dbname);


/* Database connection using PDO */
try {
    $pdo = new PDO("mysql:host=" . DB_SERVER . ";dbname=" . DB_NAME, DB_USERNAME, DB_PASSWORD);
    // Set the PDO error mode to exception
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
    die("ERROR: Could not connect. " . $e->getMessage());
}
?>