i have to backup my database via php codes but i always ended up with an empty file?

<?php
include "connection.php";
$command = 'mysqldump -u root -p ***** –all-databases > dump.sql';
exec($command) or die(mysql_error());

?>

any help would be great

Recommended Answers

I don't think or die(mysql_error() works here because you access the mysql not though php but though the shell.
to get te result back from the shell

exec('command', $result);
var_dump($result);
Jump to Post

how about use this its more secure and effecive,
http://davidwalsh.name/backup-mysql-database-php
because maybe your host closed the excute command for php files.

Jump to Post

All 6 Replies

I don't think or die(mysql_error() works here because you access the mysql not though php but though the shell.
to get te result back from the shell

exec('command', $result);
var_dump($result);

that code help me in showing the errors. but the file is 0kb that mean's it is empty. i want to backup all my database on my system instead of going over the cpanel again and again every day

and what are the error that you are getting?

i have no errors. the code works but it cannot save the database into an .sql file

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.