Skip to content

Instantly share code, notes, and snippets.

@sdaoudi
Created November 10, 2021 21:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sdaoudi/4b805f01ead17bbee50ff33afd231d3b to your computer and use it in GitHub Desktop.
Save sdaoudi/4b805f01ead17bbee50ff33afd231d3b to your computer and use it in GitHub Desktop.
Simple script to dump mysql databse
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$database = 'database_name';
$user = 'user';
$pass = 'password';
$host = 'localhost';
$filename = "/backup-" . date("dmYHis") . ".sql";
$dir = dirname(__FILE__).$filename;
exec("mysqldump --user={$user} --password={$pass} --host={$host} {$database} --result-file={$dir} 2>&1", $output);
echo "<h3>Backing up database to `<code>{$dir}</code>`</h3>";
echo "<a href='$filename'>Download dump file</a><br/>";
var_dump($output);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment