码迷,mamicode.com
首页 > 数据库 > 详细

PHP使用外部命令导出数据库,备份到服务器并下载到本地

时间:2015-04-13 20:24:52      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:

<?php

    // $dumpFileName目录要有可写权限
    $DbHost = ‘localhost‘;
  $DbUser  = ‘root‘;
  $DbPwd   = ‘123456‘;
  $DbName  = ‘a‘;
   $fileName = $DbName . ‘_MySQL_data_backup_‘ . date(‘YmdHis) . ‘.sql‘;
  $dumpFileName= "/var/$fileName";


  header("Content-Disposition: attachment; filename=" . $fileName);
  header("Content-type: application/octet-stream");
  header("Pragma:no-cache"); 
  header("Expires:0");
    
  echo `mysqldump -h $DbHost -u$DbUser -p$DbPwd $DbName > $dumpFileName`;
    
  $hd = fopen($dumpFileName, ‘rb‘);
  echo fread($hd, filesize($dumpFileName));
  fclose($hd);    
 
?>

 

PHP使用外部命令导出数据库,备份到服务器并下载到本地

标签:

原文地址:http://www.cnblogs.com/gentsir/p/4422900.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!