PHP使用外部命令导出数据库,备份到服务器并下载到本地,php外部命令_PHP教程
程序员文章站
2024-01-06 15:17:40
...
PHP使用外部命令导出数据库,备份到服务器并下载到本地,php外部命令
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);
?>
下一篇: 这段代码为啥不能输出值?求教大神