View file File name : update_db_v4.php Content :<?php require 'db_config.php'; header('Content-Type: text/plain'); echo "Omni Rewards - Database Updater V4 (POS API Key)\n"; echo "=================================================\n\n"; try { $conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) { throw new Exception("Connection failed: " . $conn->connect_error); } echo "Successfully connected to the database.\n\n"; $table_name = 'business_settings'; $column_name = 'api_key'; // CORRECTED: VARCHAR requires a length, e.g., VARCHAR(64) $column_definition = "VARCHAR(64) NULL DEFAULT NULL"; $existing_columns = []; $result = $conn->query("SHOW COLUMNS FROM `$table_name`"); if ($result) { while ($row = $result->fetch_assoc()) { $existing_columns[] = $row['Field']; } } else { throw new Exception("Could not describe table `$table_name`. Does it exist?"); } echo "Checking for column `$column_name` in table `$table_name`...\n"; if (!in_array($column_name, $existing_columns)) { $sql = "ALTER TABLE `$table_name` ADD COLUMN `$column_name` $column_definition"; echo "Attempting to add column: `$column_name`... "; if ($conn->query($sql) === TRUE) { echo "SUCCESS.\n"; echo "Attempting to generate initial API key... "; $initial_key = bin2hex(random_bytes(16)); $update_sql = "UPDATE `$table_name` SET `$column_name` = '$initial_key' LIMIT 1"; if ($conn->query($update_sql) === TRUE) { echo "SUCCESS.\n"; } else { echo "FAILED. Please generate one from the admin dashboard.\n"; } echo "\n---------------------------------------\n"; echo "Database schema updated successfully.\n"; echo "You can now safely delete this file (update_db_v4.php).\n"; } else { throw new Exception("Error adding column `$column_name`: " . $conn->error); } } else { echo "Column `$column_name` already exists. No changes needed.\n"; } $conn->close(); } catch (Exception $e) { http_response_code(500); echo "\n\nAN ERROR OCCURRED:\n" . $e->getMessage() . "\n"; } ?>