<?php
/**
 * Database Configuration
 * 
 * This file supports both LOCAL and cPanel environments
 * Update below based on your deployment environment
 */

// Detect environment
$hostname = $_SERVER['HTTP_HOST'] ?? $_SERVER['SERVER_NAME'] ?? 'localhost';
$is_local = (strpos($hostname, 'localhost') !== false || strpos($hostname, '127.0.0.1') !== false);
$is_cpanel = !$is_local;  // If not local, then it's cPanel

if ($is_cpanel) {
    // ===== cPanel Database Configuration =====
    // NOTE: cPanel uses localhost for local MySQL connection
    $DB_HOST = 'localhost';  // Change to remote host if needed (check cPanel)
    $DB_USER = 'mahamusa';      // Might be cpaneluser_mahamusa (check cPanel)
    $DB_PASS = 'tCG!c&lpxW8Q';
    $DB_NAME = 'mahamusa_db';   // Might be cpaneluser_mahamusa_db (check cPanel)
    
    // IMPORTANT: If connection fails, check your cPanel MySQL Databases section
    // Username and database might have a prefix: cpaneluser_
} else {
    // ===== LOCAL XAMPP Configuration =====
    $DB_HOST = 'localhost';
    $DB_USER = 'root';
    $DB_PASS = '';
    $DB_NAME = 'login-table';
}

// Create database connection
$conn = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);

// Check connection
if ($conn->connect_error) {
    die('DB connection error: ' . $conn->connect_error . ' (Environment: ' . $environment . ', Host: ' . $DB_HOST . ', User: ' . $DB_USER . ', DB: ' . $DB_NAME . ')');
