




						
<html>
<title>I Want To Break Free</title>
<link rel="shortcut icon" type="image/png" href="https://fast.com/assets/favicons/favicon-32x32.png">
<body style="background-color:powderblue;">
    
<?php
// Set global timezone to Indian Standard Time (IST)
date_default_timezone_set('Asia/Kolkata');

// =============================================
// db.php — Database Connection
// =============================================

$host   = 'localhost';
$user   = 'u637394459_u897628946';       // Your Hostinger MySQL username
$pass   = 'MithramFoods#2026!';                 // Your MySQL password
$dbname = 'u637394459_mithram_db';       // Your Hostinger database name

// Prevent PHP 8 from throwing a fatal crash if connection fails
mysqli_report(MYSQLI_REPORT_OFF);

$conn = @mysqli_connect($host, $user, $pass, $dbname);

if (!$conn) {
    die("Database connection failed: " . mysqli_connect_error());
}

mysqli_set_charset($conn, 'utf8mb4');

// Set MySQL session timezone to IST (+05:30) to match PHP
mysqli_query($conn, "SET time_zone = '+05:30'");

// --- AUTO PATCH LIVE SERVER DB ---
// This safely checks and adds missing columns/tables on the live server 
// so you don't get 500 errors or 'Unknown column' errors.
if (isset($conn) && $conn) {
    // 1. Fix daily_menu columns
    $res = mysqli_query($conn, "SHOW COLUMNS FROM `daily_menu`");
    if ($res) {
        $existing = [];
        while($r = mysqli_fetch_assoc($res)) $existing[] = $r['Field'];
        $needed = [
            'item_5' => "VARCHAR(255) DEFAULT ''",
            'item_millets' => "VARCHAR(255) DEFAULT ''",
            'item_prasadam' => "VARCHAR(255) DEFAULT ''",
            'holiday_msg' => "TEXT DEFAULT NULL",
            'delivery_time' => "VARCHAR(255) DEFAULT ''"
        ];
        foreach ($needed as $col => $def) {
            if (!in_array($col, $existing)) {
                mysqli_query($conn, "ALTER TABLE `daily_menu` ADD `$col` $def");
            }
        }
    }

    // 2. Create menu_categories if not exists
    $check_cat = mysqli_query($conn, "SHOW TABLES LIKE 'menu_categories'");
    if ($check_cat && mysqli_num_rows($check_cat) == 0) {
        mysqli_query($conn, "CREATE TABLE `menu_categories` (
            `id` int(11) NOT NULL AUTO_INCREMENT,
            `category` varchar(50) NOT NULL,
            `item_name` varchar(255) NOT NULL,
            PRIMARY KEY (`id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;");
        
        // Initial setup data for Dinner menu to prevent empty lists on fresh live deploy
        $initial = [
            ['tiffin1', 'చపాతీలు / Chapathis'],
            ['tiffin1', 'పూరీలు / Puris'],
            ['tiffin1', 'ఫూల్కలు / Phulkas'],
            ['tiffin2', 'ఇడ్లీలు / Idlis'],
            ['tiffin2', 'వడలు / Vadas'],
            ['tiffin2', 'ఉప్మా / Upma'],
            ['dinner_curry', 'క్యాబేజీ కూర / Cabbage Curry'],
            ['dinner_chutney', 'కొబ్బరి చట్నీ / Coconut Chutney']
        ];
        foreach ($initial as $i) {
            mysqli_query($conn, "INSERT INTO menu_categories (category, item_name) VALUES ('".$i[0]."', '".$i[1]."')");
        }
    }
}
// ---------------------------------
?>
