0

I am using the following code to try and execute a mysqldump to save my tables and information. Of course my username and password are included from my database class and they work fine.

$string = 'mysqldump -u'.$db->user.' -p'.$db->pass.' '.$db->db.' > /home/user/public_html/'.$filename;
$result=exec($string,$output);
if($output==''){ echo "Error"; }
else { echo "GOOD"; }

The script echo's the "GOOD" remark however the log file is empty. However if I run the string:

'mysqldump --help > /home/user/public_html/'.$filename;

It will print the help information to the file. So I have to ask, why isn't it working otherwise? Am I missing something as it did seem pretty straight forward.

Dawson Irvine
  • 322
  • 4
  • 19
  • Have you tried turning on error reporting to see if you get any errors running the above? – Cyclonecode Jan 14 '18 at 00:47
  • Try to run the command inside your shell. Maybe it writes to stderr without returning an error. You could also try to send stderr to the file as well (https://stackoverflow.com/questions/876239/how-can-i-redirect-and-append-both-stdout-and-stderr-to-a-file-with-bash). You might get at least some output. – Jonas Osburg Jan 14 '18 at 00:51
  • @Cyclonecode Yes, I have done the following so far: `$string = '/usr/bin/mysqldump --password=\''.$db->pass.'\' --user='.$db->user.' '.$db->db.' --single-transaction >/home/dnidesig/public_html/'.$filename.' 2>&1';` and have gotten the error that `Warning: Using a password on the command line interface can be insecure. mysqldump: Got error: 1045: Access denied for user 'dnidesig_dniroot'@'localhost' (using password: YES) when trying to connect` – Dawson Irvine Jan 14 '18 at 00:57
  • However, my password and username work with my php code and have "All Privileges" otherwise. – Dawson Irvine Jan 16 '18 at 01:33

0 Answers0