1

I am using below code to backup my database using php script but I am getting 0KB size file. How can I backup my full database with all routines and functions?

$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbname='mydatabase';
$toDay = date('d-m-Y');
//exec("mysqldump --user=$dbuser --password='$dbpass' --host=$dbhost --single-transaction $dbname > D:\Sql_Backups/".$toDay."_DB.sql");
//exec('mysqldump --user=$dbuser --password=$dbpass --host=$dbhost $dbname > D:\Sql_Backup/file.sql');
exec ("mysqldump --routines --h $dbhost --u $dbuser --p $dbpass --single-transaction $dbname  > D:\Sql_Backup/db_backup.sql");

how to create a backup database script in php and zip it How to backup MySQL database in PHP? Backup a mysql database and download as a file

3
  • Any one give me suggestions to solve my problem.. Commented Jan 4, 2014 at 12:25
  • Windows path must escape backslash ` \ ` to ` \\ ` if using double quotes. Besides that, what error do you get? What does echo exec(... print? Can you hit the command via command line from the same user? > does not pipe STDERR does it? Do you have log files? Commented Feb 25, 2014 at 11:40
  • @DanFromGermany echo exec(..) did't print anything.And it not return any error.. Commented Feb 25, 2014 at 11:48

1 Answer 1

1

There a few suggestion:
1. Compulsary to use absolute path for mysqldump.
2. Try using --opt (default option for mysqldump). Can refer http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html
3.For the option, if use short form, no need to have (--). eg: --p. Use (--) when use full form. eg: --password. So use '-p' instead of '--p' (applied for others option too).
4. try 'shell_exec' or 'system' if mysqldump doesnt work on 'exec'.
5. try avoid have space between option and variable. Eg: -p$dbpass

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

2 Comments

can you provide a example with your suggestion.
@Sumitpatel this is the issues I encountered a long time ago in stackoverflow.com/q/26749853/4216992, for point 2 - 5 you can refer to link that I provided above.

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.