Home >Backend Development >PHP Tutorial >PHP uses the mysqldump command to export the database_PHP tutorial

PHP uses the mysqldump command to export the database_PHP tutorial

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

PHP uses the mysqldump command to export the database

PHP uses external commands to export the database. The code is very simple, no more nonsense

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

// $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);

?>

1 2 3

4

6 7 8 9 10
11 12
13 14 15 16 17 18 19 20 21
<🎜> <🎜> <🎜>// 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); ?>
http://www.bkjia.com/PHPjc/983321.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/983321.htmlTechArticlePHP uses the mysqldump command to export the database. PHP uses external commands to export the database. The code is very simple, not much nonsense 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ?php // $d...
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