Lokasi:
/
home
/
u847703118
/
domains
/
alphamed.cloud
/
public_html
/
Ubah: restore_database.php
<?php require 'db_connect.php'; // Default restore file $defaultFile = 'database_deployment.sql'; // Check for command line argument or use default $file = isset($argv[1]) ? $argv[1] : $defaultFile; if (!file_exists($file)) { echo "Error: File '$file' not found.\n"; echo "Usage: php restore_database.php [filename.sql]\n"; echo "Available .sql files:\n"; foreach (glob("*.sql") as $f) echo "- $f\n"; foreach (glob("database/*.sql") as $f) echo "- $f\n"; exit(1); } echo "WARNING: This will overwrite the database with data from '$file'.\n"; echo "Are you sure? (Type 'yes' to confirm): "; $handle = fopen ("php://stdin","r"); $line = fgets($handle); if(trim($line) != 'yes'){ echo "ABORTED.\n"; exit; } echo "Restoring from $file...\n"; // Read the entire file $sql = file_get_contents($file); try { // Enable multiple statements emulation if not already $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1); // Execute the SQL $pdo->exec($sql); echo "Database restored successfully from $file.\n"; } catch (PDOException $e) { echo "Error restoring database: " . $e->getMessage() . "\n"; // Attempt to give more context if possible, but with exec on a big string it's hard. } ?>
Batal