exec("CREATE DATABASE IF NOT EXISTS `$name` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci"); $pdo = new PDO("mysql:host=$host;dbname=$name", $user, $pass); $config_content = " PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, ]); } return \$pdo; } require_once __DIR__ . '/../includes/functions.php'; "; file_put_contents($config_file, $config_content); header("Location: install.php?step=2"); exit; } catch (Exception $e) { $error = "Database Connection Failed: " . $e->getMessage(); } } elseif ($step === 2) { require_once $config_file; try { $pdo = db(); // 1. Run Base Schema $schema = file_get_contents(__DIR__ . '/db/schema.sql'); $pdo->exec($schema); // 2. Run Migrations $migrations_dir = __DIR__ . '/db/migrations/'; $migrations = glob($migrations_dir . '*.sql'); sort($migrations); foreach ($migrations as $migration) { $sql = file_get_contents($migration); if (!empty(trim($sql))) { $pdo->exec($sql); } } // 3. Seed initial data (from init.php logic) $stmt = $pdo->query("SELECT COUNT(*) FROM outlets"); if ($stmt->fetchColumn() == 0) { $pdo->exec("INSERT INTO outlets (name, address) VALUES ('Main Downtown', '123 Main St'), ('Westside Hub', '456 West Blvd')"); $pdo->exec("INSERT INTO categories (name, sort_order) VALUES ('Burgers', 1), ('Sides', 2), ('Drinks', 3)"); $pdo->exec("INSERT INTO products (category_id, name, description, price) VALUES (1, 'Signature Burger', 'Juicy beef patty with special sauce', 12.99), (1, 'Veggie Delight', 'Plant-based patty with fresh avocado', 11.50), (2, 'Truffle Fries', 'Crispy fries with truffle oil and parmesan', 5.99), (3, 'Craft Cola', 'House-made sparkling cola', 3.50)"); } header("Location: install.php?step=3"); exit; } catch (Exception $e) { $error = "Initialization Failed: " . $e->getMessage(); } } elseif ($step === 3) { require_once $config_file; $username = $_POST['admin_user'] ?? ''; $password = $_POST['admin_pass'] ?? ''; $email = $_POST['admin_email'] ?? ''; if (empty($username) || empty($password)) { $error = "Username and Password are required."; } else { try { $pdo = db(); $hashed_pass = password_hash($password, PASSWORD_DEFAULT); // Ensure Admin group exists $stmt = $pdo->prepare("SELECT id FROM user_groups WHERE name = 'Administrator' LIMIT 1"); $stmt->execute(); $group_id = $stmt->fetchColumn(); if (!$group_id) { $pdo->exec("INSERT INTO user_groups (name, permissions) VALUES ('Administrator', 'all')"); $group_id = $pdo->lastInsertId(); } $stmt = $pdo->prepare("INSERT INTO users (group_id, username, password, full_name, email, is_active) VALUES (?, ?, ?, ?, ?, 1)"); $stmt->execute([$group_id, $username, $hashed_pass, 'Super Admin', $email]); header("Location: install.php?step=4"); exit; } catch (Exception $e) { $error = "Failed to create Admin: " . $e->getMessage(); } } } } ?>
Enter your database connection details.
Ready to create tables and run migrations. This will set up the latest database structure.
Create your first administrator account.
The system has been successfully installed.
install.php file from your server immediately!