Php MySQL数据库客户端下载

Php MySQL数据库客户端下载,php,mysql,Php,Mysql,我用这些代码在服务器端下载MySQL数据库,它工作正常,但我不知道如何在客户端下载数据库,请帮助 include'connect.php'; if(isset($_POST['download'])){ $time = time(); $current_date_time = date('d-m-Y@H-i-s', strtotime('+3 hours')); $backupFile = 'D://xampp//htdo

我用这些代码在服务器端下载MySQL数据库,它工作正常,但我不知道如何在客户端下载数据库,请帮助

        include'connect.php';
    if(isset($_POST['download'])){

        $time = time();
        $current_date_time = date('d-m-Y@H-i-s', strtotime('+3 hours'));
        $backupFile = 'D://xampp//htdocs//development//ShahrajeTraders//backup//'.$database.'~'.$current_date_time.'.sql';
        $command = "D://xampp//mysql//bin//mysqldump.exe -h $host_name -u $user_name -p$user_pass $database > $backupFile";
        system($command);

        if($command){
            echo'
            <script>
                $(document).ready(function(){
                    alert("Download Completed.");   
                }); 
            </script>
            ';          
        }else{
            echo'               
            <script>
                $(document).ready(function(){
                    alert("Error During Downloading."); 
                }); 
            </script>
            ';
        }
    } 
包括'connect.php';
如果(isset($_POST['download'])){
$time=time();
$current\u date\u time=日期('d-m-Y@H-i-s',标准时间('+3小时');
$backupFile='D://xampp//htdocs//development//ShahrajeTraders//'.$database'.~'.$current_date_time'..sql';
$command=“D://xampp//mysql//bin//mysqldump.exe-h$host\u name-u$user\u name-p$user\u pass$database>$backupFile”;
系统($指挥);
如果($command){
回声'
$(文档).ready(函数(){
警报(“下载完成”);
}); 
';          
}否则{
回声'
$(文档).ready(函数(){
警报(“下载时出错”);
}); 
';
}
} 

您需要将浏览器指向备份文件的URL

我假设您已经将内容发送到浏览器(比如,您在编写代码之前进行了回显调用),因此可以使用JavaScript为客户端(浏览器)设置一个位置

在你的情况下,它可能看起来像这样

if($command){
        echo'
        <script>
            $(document).ready(function(){
                window.location="/development/ShahrajeTraders/backup/'.$database.'~'.$current_date_time.'.sql";
            }); 
        </script>
        ';          
    }else{
        echo'               
        <script>
            $(document).ready(function(){
                alert("Error During Downloading."); 
            }); 
        </script>
        ';
    }
if($command){
回声'
$(文档).ready(函数(){
window.location=“/development/ShahrajeTraders/backup/”.$database.~'.$current\u date\u time..sql”;
}); 
';          
}否则{
回声'
$(文档).ready(函数(){
警报(“下载时出错”);
}); 
';
}

我不知道您的web服务器的配置,因此您需要调整代码中的URL。

只需打开文件并将数据流传输给用户即可?重复btw: