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

Community
  • 1
  • 1
Surendra
  • 84
  • 8
  • Any one give me suggestions to solve my problem.. – Surendra Jan 04 '14 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? – Daniel W. Feb 25 '14 at 11:40
  • @DanFromGermany echo exec(..) did't print anything.And it not return any error.. – Surendra Feb 25 '14 at 11:48

1 Answers1

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

Salehin Rafi
  • 351
  • 2
  • 6
  • 16