<?php
// Database configuration from config.php
$config = require '../../../../../../../../../../../../../app/config.php';

// Database connection
$conn = new PDO(
    'mysql:host=' . $config['db']['host'] . ';dbname=' . $config['db']['name'] . ';charset=' . $config['db']['charset'],
    $config['db']['user'],
    $config['db']['pass']
);

// Function to sanitize file names
function sanitizeFileName($fileName) {
    return preg_replace("/[^a-zA-Z0-9]+/", "", $fileName);
}

// Export the entire database as a downloadable SQL file
$exportFileName = 'database_export_' . date('Y-m-d_H-i-s') . '.sql';
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . $exportFileName . '"');
$exportCommand = 'mysqldump -h ' . $config['db']['host'] . ' -u ' . $config['db']['user'] . ' -p"' . $config['db']['pass'] . '" ' . $config['db']['name'];
passthru($exportCommand);
?>
