0

I have used the following to check if exec() is enabled on my server:

public function exec_enabled() {
  $disabled = explode(',', ini_get('disable_functions'));
  return !in_array('exec', $disabled);
}

And I found out that it was enabled on my server. Now I am trying to run the following, and the database isn't getting backed up:

exec('mysqldump --user=foo --password=bar --host=localhost foobar > backup.sql');

I have also tried

exec('mysqldump -u foo -p bar foobar > backup.sql');

But it didn't work either. Also, I am not getting any errors (error reporting is on). Can anyone please tell me what am I doing wrong here?

Kamran Ahmed
  • 11,809
  • 23
  • 69
  • 101

4 Answers4

0

Syntax:

mysqldump -u username -ppass_word database_name table_name > path/sql_file_name.sql
nKn
  • 13,691
  • 9
  • 45
  • 62
Mahavir
  • 322
  • 4
  • 8
0

This should work -

exec('mysqldump -u foo --password=bar --host=localhost foobar > backup.sql');
CS GO
  • 914
  • 6
  • 20
0

In *nix systems, use the WHICH command to show the location of the mysqldump, try this :

<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'password';
$dbname = 'test';
$mysqldump=exec('which mysqldump');

$backup_file = $dbname .'.gz';
$command = "$mysqldump --opt -h $dbhost -u $dbuser -p $dbpass ".
           "test_db | gzip > $backup_file";

exec($command);
?>
user3004356
  • 870
  • 4
  • 16
  • 49
0

putting the complete path to mysql dump seems to work

exec('complete\path\to\mysqldump.exe -uUSERNAME -pPASSWORD DATABASE_NAME > output_folder_path/filename.sql');