tags:

views:

65

answers:

2

Please help, I got this code from googling on how to use mysql dump on php. But its just generating a blank .sql file. I already tried putting the mysqldump.exe on the same directory as the php file but doesn't work.

<?php
system('mysqldump -uroot -pmypassword test > C:\wamp\www\test\test.sql');
?>

I'm trying to do this, but I am running windows 7 and I get access denied error if I change the privileges in cmd.exe even if I'm the admin.

Please help, why is it generating a blank sql file? How do I solve this?

+1  A: 

You should check the return value from the "system" operation. You should check your file path. You should check the database exists.

A good way to verify all that is to execute this command by hand, before using it in php.

Guillaume Lebourgeois
yep, I tried it on cmd but it will always prompt for the password if you do it like this-p mypasswordIf I do it like this, I will get error saying that access denied using password yes-pmypassword
The right syntax is -pmypassword , without the space. Can give us the exact error message when you do this this way ?
Guillaume Lebourgeois
it says:got error 1045:access denied for user 'root@localhost' using password: yes when trying to connect
thanks, the problem was this -uroot, should be -u root
+2  A: 

Try putting a space between the -u and your username

<?php
system('mysqldump -u root -pmypassword test > C:\wamp\www\test\test.sql');
?>
Aaron W.