php exec() - mysqldump creates an empty file
19,559
Solution 1
These are the parameters
-uROOT -pPASSWORD --databases DB --result-file=FILE.SQL
Solution 2
Try this one:
$command = 'd:\xampp\mysql\bin\mysqldump --opt -u '.$_user.' -p'.$_pass.' '.$_db.' > test.sql 2>&1';
-its about permission issue.
Author by
Reteras Remus
Updated on June 05, 2022Comments
-
Reteras Remus almost 2 years
I want to create a backup from a database, but I get only a blank file.
include('config.php'); $command = "mysqldump --opt -h ".$_host." -u ".$_user." -p ".$_pass." ".$_db." > test.sql"; exec($command); echo "<br />".$command;
test.sql is created where the .php file is located.
Edit:
Note! I'm using XAMPP WINDOWS !
Solution:
Because I'm using a Windows Web Server (XAMPP), I needed to specify the path:
$command = 'd:\xampp\mysql\bin\mysqldump --opt -u '.$_user.' -p'.$_pass.' '.$_db.' > test.sql';
- I removed the space between the -p and the pass. It looks like:
-pMYPASSWORD
- Replaced
"
with'
I think if you are using a Linux based web server, you don't have to specify the path for mysqldump.
Cheers! :-)
- I removed the space between the -p and the pass. It looks like: