Skip to content

Instantly share code, notes, and snippets.

@fchaussin
Created September 23, 2019 05:40
Show Gist options
  • Save fchaussin/fb8cd7c1d7af513afe695ba10bd6782c to your computer and use it in GitHub Desktop.
Save fchaussin/fb8cd7c1d7af513afe695ba10bd6782c to your computer and use it in GitHub Desktop.
Export MySql/MariaDb dump
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$database = 'dbname';
$user = 'user';
$pass = '***';
$host = 'localhost';
$now = date('Ymdhis');
$dir = dirname(__FILE__) . "/dump{$now}.sql";
echo "<h3>Export database to `<code>{$dir}</code>`</h3>";
exec("mysqldump --user={$user} --password={$pass} --host={$host} {$database} --result-file={$dir} 2>&1", $output);
var_dump($output);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment