exec($sql); $output[] = "Executed migration: " . basename($file); } } return ['success' => true, 'output' => $output]; } catch (Exception $e) { return ['success' => false, 'error' => "Database migration failed: " . $e->getMessage()]; } } // If the script is run directly from the command line, execute the migrations. if (php_sapi_name() === 'cli') { $result = run_migrations(); if ($result['success']) { foreach ($result['output'] as $line) { echo $line . " "; } echo "Migrations completed successfully. "; } else { echo $result['error'] . " "; } }