Hye, I'm new in PHP and trying to use mysqldump using php script.
I already try using command and the dump process is success.
The situation is, when I tried dump using my local computer, the dump is succeed.
But when the code is transfer into the server, mysqldump doesn't work. I have tried almost the solution related to mysqldump topics, but still it doesn't work. I hope someone can guide me. TQ
<?php
/*-----------------------------------------------
MYSQLDUMP FOR SERVER
------------------------------------------*/
$dbhost = "*****";
$dbuser = "*****";
$dbpass = "*****";
$dbname = "*****";
//set date today
$today=date("d-m-Y");
//set file name
$filename = "leave_".$today.".sql";
//MYSQLDUMP
//For Server
$command = sprintf("/usr/bin/mysqldump --opt -h%s -u%s -p%s %s >/var/www/html/leave/leave/backup/%s",
//for local
//$command = sprintf("c:\AppServ\MySQL\bin\mysqldump --opt -h%s -u%s -p%s %s > %s",
$dbhost,
$dbuser,
$dbpass,
$dbname,
$filename
);
system($command);
/*-------------------------------------------------------------
TO SAVE FILE SQL INTO LOCAL
---------------------------------------------------------------*/
$file = "leave_".$today.".sql";
if(!$file)
{
// File doesn't exist, output error
die('File not found');
}
else
{
// Set headers to ask user where to save file.
header('Pragma: anytextexeptno-cache', true);
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private", false);
header("Content-Type: text/plain");
header("Content-Disposition: attachment; filename=$file");
// Read the file from disk
readfile($file);
}
?>