<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>
以上就介紹了PHP使用外部命令導出資料庫,備份到伺服器並下載到本地,包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。