ThinkPHP uses pclzip to package and back up mysql databases

Source: Internet
Author: User
Tags decompress zip
This article describes how thinkPHP uses pclzip to package and back up mysql databases. it analyzes thinkPHP's skills in using pclzip to compress files in the form of examples, for more information about how thinkPHP uses pclzip to package and back up mysql databases, see the following example. We will share this with you for your reference. The details are as follows:

PclZip introduces how to compress and decompress Zip files (WinZip and PKZIP) in the PclZip library and process such files, this includes generating compressed files, listing compressed files, and extracting files.

Database Backup is a very important thing. many backup methods also use vps for direct backup, and some use phpmyadmin for data backup. The small editor thinks this is troublesome and the backed up SQL file is too large to occupy a certain amount of space. Therefore, using pclzip to compress SQL files saves some space. Before Xiaobian has written database backup code here will not repeat, Pclzip official: http://www.phpconcept.net/pclzip/pclzip-downloads (the latest version of 2-8-2 ).
This site.

Find file_put_contents in the DatabaseAction. class. php file and add the following code below:

Import ("ORG. util. pclZip "); $ archive = new PclZip ('. /data /'. date ("y-m-d" ).'.zip '); $ v_list = $ archive-> create ($ dir); if (file_exists ($ dir) & $ v_list! = 0) {$ this-> success ("backup succeeded & compressed");} else {die ("Error :". $ archive-> errorInfo (true); $ this-> error ("backup failed ");}

And delete the original DatabaseAction. class. php if.

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.