Good morning!
I'm trying to create a PHP page that I can use to back up all my MySQL databases and gzip the file. The problem that I'm having is that when I call exec() to execute my command, any output gets written to the screen, not to my output array. Also, my return value is always 0, even if there are errors. Here's my code:
$strCommand = "mysqldump --verbose --quick --host=$strHostName --user=$strUserName --password=$strPassword --all-databases | gzip > $strBackupFile";
echo "-------------START-------------\n";
$strOutput = exec($strCommand,$arrOutput,$intReturnValue);
echo "COMMAND: $strCommand\n\n";
echo "RETURN VALUE: $intReturnValue\n\n";
echo "OUTPUT: \n";
print_r($arrOutput);
echo "-------------END-------------\n";
die();
If I force an error by using the wrong password for instance, I get the following:
-------------START-------------
-- Connecting to XXXX...
mysqldump: Got error: 1045: Access denied for user 'XXXX'@'XX.XX.XX.XX' (using password: YES) when trying to connect
COMMAND: mysqldump --verbose --quick --host=XXXX --user=XXXX --password=XXXX --all-databases
RETURN VALUE: 2
OUTPUT:
Array
(
)
-------------END-------------
Obviously I'm OK with the error, but I need it in $arrOutput, not on the screen.
If I modify my code to run this instead, $arrOutput is populated as expected:
$strCommand = "mysqldump --help";
From what I can gather, it's something with my original command line, but I can't seem to figure out exactly what.
Also, can anyone tell me where I could find a list of mysqldump return codes?
Thanks in advance for any assistance!!