Skip to content

Instantly share code, notes, and snippets.

@guillaumepiot
Created March 25, 2014 12:07
Show Gist options
  • Save guillaumepiot/9760507 to your computer and use it in GitHub Desktop.
Save guillaumepiot/9760507 to your computer and use it in GitHub Desktop.
PHP - Dump MySQL
<?php
$DBUSER="user";
$DBPASSWD="password";
$DATABASE="user_db";
$filename = "backup-" . date("d-m-Y") . ".sql.gz";
$mime = "application/x-gzip";
header( "Content-Type: " . $mime );
header( 'Content-Disposition: attachment; filename="' . $filename . '"' );
$cmd = "mysqldump -u $DBUSER --password=$DBPASSWD $DATABASE | gzip --best";
passthru( $cmd );
exit(0);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment