<?php
// ============================================================
//  Turi Express Courier Services — Database Connection (PDO)
//  File: includes/db.php
// ============================================================

require_once __DIR__ . '/config.php';

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,
        ]
    );
} catch (PDOException $e) {
    // In production you would log this; never expose credentials
    die('<div style="font-family:sans-serif;padding:30px;color:#c00;">
        <h2>Database Connection Error</h2>
        <p>Could not connect to the database. Please check your <code>includes/config.php</code> settings.</p>
        <p><small>' . htmlspecialchars($e->getMessage()) . '</small></p>
    </div>');
}
