Skip to content

Instantly share code, notes, and snippets.

@johnulist
Forked from micc83/mysqldump.php
Last active July 19, 2020 16:53
Show Gist options
  • Save johnulist/4084435ce5b0691d68965aa8eb5c8f39 to your computer and use it in GitHub Desktop.
Save johnulist/4084435ce5b0691d68965aa8eb5c8f39 to your computer and use it in GitHub Desktop.
Simple PHP script to dump a MySql database
<?php
//Other solutions
/*
1- https://github.com/spatie/db-dumper
2- https://github.com/ifsnop/mysqldump-php
3-
*/
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$database = 'db';
$user = 'user';
$pass = 'pass';
$host = 'localhost';
$dir = dirname(__FILE__) . '/dump.sql';
echo "<h3>Backing up 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