萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> php編程 >> PHP使用mysqldump命令導出數據庫

PHP使用mysqldump命令導出數據庫

 PHP使用外部命令導出數據庫,代碼很簡單,就不多廢話了

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 <?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); ?>
copyright © 萬盛學電腦網 all rights reserved