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

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top