Use the mysqldump command in PHP to export the database.

Source: Internet
Author: User
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.

,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.