Recently, I used php to write a data backup function. The method is to use the php system function to execute the mysqldump command for backup. Here we will share it with you. If you need it, refer to it.
Recently, I used php to write a data backup function. The method is to use the php system function to execute the mysqldump command for backup. Here we will share it with you. If you need it, refer to it.
PHP uses external commands to export the database. The code is very simple, so there is not much nonsense.
<? Php // $ dumpFileName directory must have the write permission $ DbHost = 'localhost'; $ DbUser = 'root'; $ DbPwd = '000000'; $ 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 $ D BUser-p $ DbPwd $ DbName> $ dumpFileName '; $ hd = fopen ($ dumpFileName, 'rb'); echo fread ($ hd, filesize ($ dumpFileName )); fclose ($ hd);?>
The above is all the content described in this article. I hope you will like it.
,