I write some code with PHP to backup database.
Here my code:
exec("mysqldump --opt -h localhost -u root test > mydb.sql");
But I get 0-byte in my file (mydb.sql). I also run with passthru(), system(), but it still gets 0-byte.
I try to use command. It works.
I use the lastest XAMPP for my localhost.
So, how can I do to make it works correctly?
It's likely a permissions issue, or the fact you're not passing a password. To see errors, route STDERR to STDOUT using 2>&1
exec("mysqldump --opt -h localhost -u root test > mydb.sql 2>&1", $output);
print_r($output);
This will show you the errors you'd normally see on the command line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With