S
|
stiven 5/6/2012 |
Thanks for this great tip. however it isn't working for me, the sql file that is being downloaded is blank. 0 bytes. it has no content. am i doing something wrong? i created a folder backup on the server and i put the file backup.php there. the permissions for this folder are set as 755 when I click on the link the file downloads but it has no content. if i set the backup folder permissions to 777 I get a 500 Internal Server Error when i click the link. |
![]() |
Admin 5/7/2012 |
You need to explain which version of script you use. They require different setup. |
S
|
stiven 5/7/2012 |
Thanks for the help. I used the second one no zipping and i found the problem the user, host, and password needed to be in single quotes, at least that worked for me
|
S
|
swanside 9/17/2012 |
Hi, <?php ob_start(); $username = "root"; $password = ""; $hostname = "localhost"; $dbname = "rigwork"; // if mysqldump is on the system path you do not need to specify the full path // simply use "mysqldump --add-drop-table ..." in this case $command = "C:\\xampp\\mysql\\bin\\mysqldump --add-drop-table --host=$hostname --user=$username "; if ($password) $command.= "--password=". $password ." "; $command.= $dbname; system($command); $dump = ob_get_contents(); ob_endclean(); // the database dump now exists in the $dump variable // saving it to the file $dumpfname = $dbname . "" . date("Y-m-dH-i-s").".sql"; $fp = fopen($dumpfname, "w"); fputs($fp, $dump); fclose($fp); // zip the dump file $zipfname = $dbname . "" . date("Y-m-d_H-i-s").".zip"; $zip = new ZipArchive(); if($zip->open($zipfname,ZIPARCHIVE::CREATE)) { $zip->addFile($dumpfname,$dumpfname); $zip->close(); } // read zip file and send it to standard output if (file_exists($zipfname)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.basename($zipfname)); flush(); readfile($zipfname); exit; } ?>
$command = "C:\\xampp\\mysql\\bin\\mysqldump --add-drop-table --host=$hostname --user=$username ";
$command = "C:\wamp\bin\mysql\mysql5.5.24\mysqldump --add-drop-table --host=$localhost --user=$root ";
|
![]() |
mbintex 6/21/2017 |
I´d like to make this script more versatile by getting the database credentials from variables like this: $username=$user;
$username=$_SESSION["user"];
|