<?php
// config/database.php

// **CRITICAL FIX: Set the default PHP time zone to Asia/Colombo.**
// This standardizes all PHP date and time calculations to the desired time zone.
date_default_timezone_set('Asia/Colombo');

// Define database connection constants
define('DB_HOST', '65.21.215.143');      // Your database host (e.g., localhost, 127.0.0.1)
define('DB_USER', 'orinstol');          // Your database username
define('DB_PASS', 'X#HIc3~RctGR');              // Your database password
define('DB_NAME', 'orinstol_lms'); // The name of your database

try {
    // Data Source Name (DSN) for MySQL
    $dsn = "mysql:host=" . DB_HOST . ";dbname=" . DB_NAME . ";charset=utf8mb4";

    // Create a new PDO instance
    $pdo = new PDO($dsn, DB_USER, DB_PASS);

    // Set PDO error mode to exception
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    // Set the default fetch mode
    $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);

    // **CRITICAL FIX: Set the MySQL connection's time zone to +05:30.**
    // This ensures consistency between the application and the database.
    $pdo->exec("SET time_zone = '+05:30'");

} catch (PDOException $e) {
    // If connection fails, terminate the script and log the error.
    die("Database connection failed: " . $e->getMessage());
}
?>