0

I tried the below code to backup my database "db_school".

<?php
    shell_exec('mysqldump -u root -h localhost db_school > backup-file.sql');
?>

The new file named "backup-file.sql" is created but, the problem is that it is totally empty. Following is my database table:

-------------------------------------
id  |  school_name   |  city
-------------------------------------
1   |  cp school     |  New York
2   |  public school |  San Fracisco
-------------------------------------

Note: my 'root' user has no password I know there are many posts on this topic but each suggests the code similar to above

2
  • There may be some error happening and is not captured anywhere, can you try 2>&1 in your command or even echo the output of the command. Commented Nov 15, 2013 at 12:00
  • the command runs successfully in shell and even I tried printing the output but it is empty either Commented Nov 15, 2013 at 12:02

2 Answers 2

1

Make sure folder having full permission (777 read/write).

because this code create new file name "backup-file.sql" , so folder having permission to create new file.

please give the permission to that folder where this php file executes.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks vishal, i think your answer will make it but I don't know how to give permissions on local machine
Which operating system you have
0

try this dear

a set of one or more complete databases

<?php
    shell_exec('mysqldump -u root -h localhost --database db_school > backup-file.sql');
?>

1 Comment

thanks for the answer but, again the same...an empty file... could there be problem with my system or xampp?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.