But adding the full paths in my php script didn't help.
rocknbil
7:11 pm on May 8, 2010 (gmt 0)
Add some error checking.
$filename = DB_NAME.date("Y-m-d-H-i-s").".sql"; $command = "mysqldump --opt -h ".DB_SERVER." -u ".DB_USER." -p ".DB_PASS." ".DB_NAME." > $filename"; system($command,$status); if ($status==FALSE) { echo "some error occurred in executing the command. The command was $command"; }
mattch80
7:34 pm on May 8, 2010 (gmt 0)
rocknbil, I tried that and it didn't return false.
Matthew1980
8:30 pm on May 8, 2010 (gmt 0)
Hi there mattch80,
Have you made sure that the actual $command var you are building is being populated as if it were being done via the cmd line? Because if it does work via the cmd line, then its down to the way the the var is being built.
Personally I would do this too, though it may have no impact, but as you are adding it... :-
Does anyone know why this works when the single dash version doesn't? (--host= instead of -h)
rocknbil
12:32 am on May 9, 2010 (gmt 0)
Well there are **two** differences there. :-) You have the full path too, it could have been that, or it could have been it's not understanding the -h switch for whatever reason. The mysqldump man page would be where to look. So you know what's happening,
system("blah > $filename");
Is trying to exec "blah" but however that works out, > will always create and dump output from blah into $filename. No output from blah . . . empty file.
Did $status return anything at all? Not that it matters . . . usually you will get some sort of return code in other languages.
mattch80
3:28 am on May 9, 2010 (gmt 0)
I did some more testing. The -p and not having the full path to mysqldump seemed to cause the problem (not sure why yet). When it's not working $status returns a 2 or 127, and when it's working a 0.
rocknbil
7:35 pm on May 9, 2010 (gmt 0)
when it's working a 0.
I wasn't surewith PHP, but I had a bit of incorrect info, $status will never be FALSE, it's system() that returns FALSE, not the command within it. $status is the code from executing the actual command. This verifies you can do
system($command,$status); if ($status > 0) { die("Command $command died with status $status"); }
What $status represents is a bit complicated and OS dependent. In perl we use an 8 bit shift or divide by 127 to get at the child error code, or more simply, print out the STDERR filehandle . . . . not sure how you'd do that in PHP.
All of which is probably unnecessary now that it is working . . . just look for $status==0 or error.
coopster
1:32 pm on May 11, 2010 (gmt 0)
If the mysqldump command is not in the system path definition/scope then you will always need the full path to the executable command. Period.
The other issue I see here is that the short version of the password switch requires no space between the switch and the argument: