<?php
/**
 * Universal DB connector for Eden Exam
 * Works with pages that expect either $mysqli or $conn (same MySQLi handle)
 * XAMPP defaults: user=root, password="" (empty)
 */

error_reporting(E_ALL);
ini_set('display_errors', 1);

// --- Update these if your DB name/credentials differ ---



$DB_HOST = 'localhost';
$DB_USER = 'edencamp_eden';  // your full cPanel username prefix + user
$DB_PASS = 'D#uVBrdpAppH^d,6';
$DB_NAME = 'edencamp_edencampus';

$mysqli  = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
if ($mysqli->connect_errno) { die("DB connect error: ".$mysqli->connect_error); }
$conn = $mysqli; // alias for old code


// Create one MySQLi connection
$mysqli = @new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
if ($mysqli->connect_errno) {
    // Friendly message + real error for debugging
    die("Database connection failed. Check includes/db.php settings. Error: " . $mysqli->connect_error);
}

// Charset & (optional) timezone
$mysqli->set_charset('utf8mb4');
// $mysqli->query("SET time_zone = '+05:30'"); // Uncomment for Asia/Colombo

// Backwards-compat alias: many admin pages use $conn
$conn = $mysqli;

/**
 * Optional: tiny helper to get the active connection
 * Usage: $db = db(); $db->query("SELECT 1");
 */
function db(): mysqli {
    global $mysqli;
    return $mysqli;
}
