0

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) { } 
3
  • There would be no output though, you are writing to a file aren't you? The .sql doesn't get created? Commented Oct 22, 2018 at 13:10
  • Given code is working properly. It will create .sql file if you have write permission on executing directory. It will throw warning related to passing password in CLI which can be removed by using .cnf file. Commented Oct 22, 2018 at 13:12
  • There would be no output though, correct. 2>&1 is redirecting the error output in the standard, since you already redirected the standard output with >$filename it looks correct that in case of you are not seing nothing , perhaps you need to use a tee to have something in the output. The standard linux command return is 0 for successfull, other values means an error and you are getting 1 but the only place where an error is shown will be inside the file redirected output. Commented Oct 22, 2018 at 13:32

1 Answer 1

1

try

exec( '/usr/bin/mysqldump --user="'.$username .'" --password="'.$password .'" "'.$database .'" > "'.$filename .'"' );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.