Friday, June 23, 2017

Download database with php script

Hello
Now I describe you how to download large database sql file in zip with php script.
This will help you in magento or large database.


Code :

<?php

$DBUSER="root";
$DBPASSWD="password";
$DATABASE="magento_dbtest";

$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 );

echo 'done';
exit(0);
?>

This will save .zip file.

No comments:

Post a Comment