Reputation: 668
i am using this command to backup my full mysql database..
$backupFile = $dbname . date("Y-m-d-H-i-s") . '.sql';
$command = "mysqldump -h$hostname -u$username -p$password $dbname > $backupFile";
system($command);
I am getting blank file.
And i am using XAMMP on windows.
I have already used exec()
but also getting blank file.
And but on shell it has successfully done.
Whats wrong in this code.
Upvotes: 1
Views: 4493
Reputation: 64399
The best thing you can do is check what is going wrong. You might even want to check outside of PHP to see what you are doing. So echo your $command, and look at it, see if it looks correct. Then use it on the commandline, see if you can get it to work.
Possible attention points:
To test your current command, you might want to do this:
- replace your system
command with an echo: echo $command;
- run the script and copy the command you see there.
- Open a terminal. (start->run->"cmd")
- goto the dir where your script is / runs.
- paste /type the command.
- check your result.
I do not know what happens when you do not have a password, but still supply the -p option. It might try and ask for a password anyway, as you've indicated you want to enter a password, but have not provided it. I do not know this for sure, that's why you might want to check it. (@wimvds confirms in the comment: if you supply a -p and no password, you'll get a "password: " dialog.)
In the commandline you can check what command you need to type to get the mysqldump to work. If that's ok, then make sure your script actually issues that command. Then test again with the script.
Upvotes: 1