A čo takto?
<?php
// Database configuration
$host = 'localhost';
$username = 'your_username';
$password = 'your_password';
$database = 'your_database_name';
// Backup configuration
$backupDir = 'path/to/backup/directory';
$backupFile = $backupDir . '/' . $database . '_' . date('Y-m-d_H-i-s') . '.sql';
// Ensure the backup directory exists
if (!is_dir($backupDir)) {
mkdir($backupDir, 0777, true);
}
// Set execution time limit to unlimited for large databases
set_time_limit(0);
// Connect to MySQL database
$conn = new mysqli($host, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Function to generate SQL file from database
function backupDatabase($conn, $backupFile) {
// Get all tables in the database
$tables = array();
$result = $conn->query("SHOW TABLES");
while ($row = $result->fetch_row()) {
$tables[] = $row[0];
}

