Home >Backend Development >PHP Tutorial >PHP uses external commands to export the database, back up to the server and download to local, php external commands_PHP tutorial

PHP uses external commands to export the database, back up to the server and download to local, php external commands_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:57:191007browse

PHP uses external commands to export the database, back up to the server and download to local, php external commands

<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 uses external commands to export the database, back up to the server and download to local, php external command? php // $dumpFileName The directory must have writable permissions $DbHost = 'localhost' ; $DbUser = 'root...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn