I am trying to use exec() in php but looks like all my efforts are in vain !!!
Please help me : What is wrong with my code?
$cmd = "mysqldump -u root my_db table1 table2 > /home/aditi/Desktop/databasedump.sql";
$res = exec($cmd , $ot , $res);
But I don’t see this file. But when I do this on console there is no problem.
Any help will be appreciated.
A few possible causes:
the password for the dump is missing:
$cmd = "mysqldump -u root -pPassword my_db table1 table2 > /home/aditi/Desktop/databasedump.sql";mysqldump is not in the path when you run a shell:
$cmd = "/usr/bin/mysqldump -u root -pPassword my_db table1 table2 > /home/aditi/Desktop/databasedump.sql";Do not forget that the webserver process runs as another user as when you run the code in a shell. Make sure the webserver user id has access to the folder for writing the dump.