...

View Full Version : mysqldump not dumping in php



adarshakb
12-19-2010, 09:35 AM
my mysql dump question is

if i execute this statement from command prompt i get a proper file dumping my database

mysqldump -h localhost -u account_login -pReplacePasswordHere test > test2010-12-19.sql

Now the same thing i have made as a php scrip as follows



system("mysqldump -h $dbhost -u $dbuser -p$dbpass $dbname > $backupfile");
echo "mysqldump -h $dbhost -u $dbuser -p$dbpass $dbname > $backupfile";


and out put is

mysqldump -h localhost -u account_login -pReplacePasswordHere test > test2010-12-19.sql

So that means i have not given any variables wrong ...

But when php executes it creates a 0kb file with no output in it. While the original cmd prmt faithfully gives the correct output...

Whats wrong?

No warnings are displayed by the way:confused:

PS: while using the optional return code part to check the return code it returned 1

Changed code =


$xxx = system("mysqldump -h $dbhost -u $dbuser -p$dbpass $dbname > $backupfile",$tmp);
echo "mysqldump -h $dbhost -u $dbuser -p$dbpass $dbname > $backupfile RETURNED $tmp, ".($xxx?"true":"false");


changed output =

mysqldump -h localhost -u account_login -pReplacePasswordHere test > test2010-12-19.sql RETURNED 1, false

jfreak53
12-19-2010, 02:32 PM
Don't know how to fix, but for some reason I have had a lot of hassle using mysqldump with the -pPassword command, linux and windows. Never seems to work for me, it should according to documentation, so it might be ignoring that option and prompting for password input, in which case your sunk, use an SH script to echo a password to prompt. Or create a user without password if your system allows this, but a huge security risk.

adarshakb
12-19-2010, 07:32 PM
actually that didnot work at all for me :(

Finally i used another script from phpclasses website and got the same job done.

I still need to findout whats wrong with this tho :confused:

djm0219
12-19-2010, 07:51 PM
Does your provider allow external programs to be run by PHP? Does your installation of PHP have safe_mode enabled?

The return of false from the system command indicates that the system call is not working. See http://us.php.net/manual/en/function.system.php for more details.

Have you tried using exec instead of system? If you're doing a DB dump you really shouldn't need anything it might return. I've been using exec via a cron to back up DBs for years without any problems/issues.

adarshakb
12-19-2010, 08:18 PM
if i use the same system() function to execute ANY other commands and output to a file i am getting proper output.
The question of hosting doesnt come here as this error is in my local comp AND host

My safe mode is off

Inigoesdr
12-20-2010, 12:45 AM
Try using the full path to mysqldump. You might also have to escape your password if it contains spaces or special characters.

adarshakb
12-20-2010, 09:41 AM
Try using the full path to mysqldump. You might also have to escape your password if it contains spaces or special characters.
If i do that how can i execute it on server then(using godaddy)? also i dont have any special characters in password so there is no problem.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum