There is my Function to download backup is sql format
public function actionBackup()
{
// Set the database access credentials
$db_host = 'localhost';
$db_username = 'root';
$db_password = '';
$db_name = 'fads';
// Set the backup filename and path
$backup_file = 'backup.sql';
$backup_path = "C:/Users/" . get_current_user() . "/Downloads/" . $backup_file;
// Execute the mysqldump command
$path = "C: xampp_7.3mysqlbin";
$command = "mysqldump -u {$db_username} -p{$db_password} {$db_name} > {$backup_path}";
// echo $path.$command;die;
exec("$path > $command");
// Send the backup file as a download
Yii::$app->response->sendFile($backup_path);
// Delete the backup file
unlink($backup_path);
}
It’s download backup.sql but its empty i don’t understand that where is my code wrong and why i received blank backup.sql
2
Answers
I was solved that problem there is my code
First look if you use correct path for command and backup file.
Avoid spaces in paths.
Try this code:
Updated the answer