phpmysqlmysql-backup

backup database using mysqldump with php not working


please i want to backup my database using php. i have tried many answered question on this similar problem but still not working.

$username = "***";
$password = '******';
$database = 'mydatabase';
$filename = date("Y-m-d_H:i:s") . ".sql";


exec("(/usr/bin/mysqldump --opt -u$username -p$password $database> $filename) 2>&1", $output, $result);

var_dump($result);
echo "<br />";
var_dump($output);
echo "<br />";

this is the response

int(1) 
array(0) { } 

Solution

  • try

    exec( '/usr/bin/mysqldump --user="'.$username .'" --password="'.$password .'" "'.$database .'" > "'.$filename .'"' );