View file File name : update_db_v2.php Content :<?php require 'db_config.php'; header('Content-Type: text/plain'); echo "Omni Rewards - Database Updater V2 (Advertisements)\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'; $columns_to_add = [ 'ad_type' => "VARCHAR(10) NOT NULL DEFAULT 'none'", 'ad_media_url' => "VARCHAR(255) NULL DEFAULT NULL", 'ad_link_url' => "VARCHAR(255) NULL DEFAULT NULL", 'ad_video_url' => "VARCHAR(255) 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?"); } $all_exist = true; foreach ($columns_to_add as $column_name => $column_definition) { echo "Checking for column `$column_name`... "; if (!in_array($column_name, $existing_columns)) { $all_exist = false; $sql = "ALTER TABLE `$table_name` ADD COLUMN `$column_name` $column_definition"; echo "Attempting to add... "; if ($conn->query($sql) === TRUE) { echo "SUCCESS.\n"; } else { throw new Exception("Error adding column `$column_name`: " . $conn->error); } } else { echo "EXISTS.\n"; } } if ($all_exist) { echo "\nAll required advertisement columns already exist. No changes needed.\n"; } else { echo "\n---------------------------------------\n"; echo "DATABASE SCHEMA UPDATED SUCCESSFULLY FOR ADVERTISEMENTS.\n"; } echo "You can now safely delete this file (update_db_v2.php).\n"; $conn->close(); } catch (Exception $e) { http_response_code(500); echo "\n\nAN ERROR OCCURRED:\n" . $e->getMessage() . "\n"; } ?>