Home >Backend Development >PHP Tutorial >PHP uses the mysqldump command to export the database_PHP tutorial
PHP uses external commands to export the database. The code is very simple, no more nonsense
4 11 12 |
<🎜> <🎜> <🎜>// The $dumpFileName directory must have writable permissions<🎜> <🎜>$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); ?> |