View file File name : _run_db_update.php Content :<?php header('Content-Type: text/plain'); require 'db_config.php'; echo "Omni-Invoice - Database Schema Updater (v2)\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"; // Start transaction $conn->begin_transaction(); echo "Starting transaction...\n"; echo "Step 1: Reading SQL update commands from _add_payments_table.sql...\n"; $sql_commands = file_get_contents('_add_payments_table.sql'); if ($sql_commands === false) { throw new Exception("Could not read the SQL update file."); } echo "Step 2: Executing SQL commands to create payments table and migrate data...\n"; if ($conn->multi_query($sql_commands)) { // Must consume all results from multi_query $i = 0; do { $i++; if ($result = $conn->store_result()) { $result->free(); } if ($conn->more_results()) { echo " - Executed command #$i successfully.\n"; } } while ($conn->next_result()); } else { throw new Exception("Error executing SQL commands: " . $conn->error); } echo "Step 2 COMPLETE. All commands executed.\n\n"; // Commit transaction $conn->commit(); echo "---------------------------------------\n"; echo "DATABASE UPDATE COMPLETE.\n"; echo "The new 'payments' table has been created, data has been migrated, and the old columns have been removed.\n"; echo "You can now safely delete this file (_run_db_update.php) and _add_payments_table.sql from your server.\n"; $conn->close(); } catch (Exception $e) { if (isset($conn) && $conn->ping()) { $conn->rollback(); echo "\nTransaction rolled back due to error.\n"; } http_response_code(500); echo "\n\nAN ERROR OCCURRED:\n" . $e->getMessage() . "\n"; } ?>