<?php
// 🔥 REAL DATABASE INJECTION ENGINE FOR DEMO ACCOUNTS
session_start();

define('DB_HOST', 'localhost');
define('DB_NAME', 'rakshita_relay');
define('DB_USER', 'rakshita_relay');
define('DB_PASS', 'rehman@169');

try {
    $pdo = new PDO("mysql:host=" . DB_HOST . ";dbname=" . DB_NAME . ";charset=utf8mb4", DB_USER, DB_PASS, [
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
        PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
    ]);
} catch (PDOException $e) {
    die("Database connection offline");
}

// 1. Unique demo identifier parameters generate karein
$demo_id = rand(1000, 9999);
$username = "DemoUser_" . $demo_id;
$email = "demo_" . $demo_id . "@onchain.trade";
$password = password_hash("demo123", PASSWORD_BCRYPT);
$demo_balance = 10000000.00; // Physical $10 Million Dollars inside DB

try {
    // 2. Database ke andar physically 10 Million balance ke sath row insert karein
    // Note: Agar aapke table mein 'is_demo' column nahi bhi hai, toh yeh query crash nahi hogi
    $stmt = $pdo->prepare("INSERT INTO users (username, email, password, balance, total_trades) VALUES (?, ?, ?, ?, 0)");
    $stmt->execute([$username, $email, $password, $demo_balance]);
    
    // Auto-generated real primary key ID fetch karein
    $new_user_id = $pdo->lastInsertId();
    
    // 3. Complete system authentic sessions sync karein
    $_SESSION['user_id'] = $new_user_id;
    $_SESSION['username'] = $username;
    $_SESSION['email'] = $email;
    $_SESSION['is_demo'] = true;
    $_SESSION['show_demo_popup'] = true;

    header("Location: dashboard.php");
    exit();

} catch (Exception $e) {
    // Agar columns dynamic mismatch hon to crash lock block:
    echo "Engine Error: " . $e->getMessage();
    exit();
}
?>