首页 >后端开发 >php教程 >PHP使用外部命令导出数据库,备份到服务器并下载到本地,php外部命令_PHP教程

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

WBOY
WBOY原创
2016-07-13 09:57:191003浏览

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

<span><?<span>php

    </span><span>//</span><span> $dumpFileName目录要有可写权限</span>
    <span>$DbHost</span> = 'localhost'<span>;
  </span><span>$DbUser</span>  = 'root'<span>;
  </span><span>$DbPwd</span>   = '123456'<span>;
  </span><span>$DbName</span>  = 'a'<span>;
   </span><span>$fileName</span> = <span>$DbName</span> . '_MySQL_data_backup_' . <span>date</span>('YmdHis) . '.sql'<span>;
  $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, </span>'rb'<span>);
  echo fread($hd, filesize($dumpFileName));
  fclose($hd);    
 
?></span></span>

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/983248.htmlTechArticlePHP使用外部命令导出数据库,备份到服务器并下载到本地,php外部命令 ? php // $dumpFileName目录要有可写权限 $DbHost = 'localhost' ; $DbUser = 'root...
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn