<?php
// 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);
    // Set the PDO error mode to exception
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    // Set default fetch mode to associative array
    $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
    // Set database session timezone to Africa/Dar_es_Salaam (+03:00)
    $pdo->exec("SET time_zone = '+03:00'");
} catch(PDOException $e) {
    die("Database connection failed: " . $e->getMessage());
}
?>

