Home > Backend Development > PHP Tutorial > thinkPHP uses pclzip package to back up mysql database

thinkPHP uses pclzip package to back up mysql database

WBOY
Release: 2016-07-29 08:51:40
Original
1096 people have browsed it

The example in this article describes how thinkPHP uses pclzip packaging to back up mysql database. Share it with everyone for your reference, the details are as follows:

PclZip introduction PclZip library can compress and decompress compressed files in Zip format (WinZip, PKZIP); and can process such files, including generating compressed files and listing compressed files. The contents of the file, decompressed files, etc.

Database backup is a very important thing. There are many ways to back up, some of which are directly backed up through vps, and some are backed up through phpmyadmin. The editor thinks this is troublesome and the backed up .sql file is too large and takes up a certain amount of space. So use pclzip to compress the sql file, which saves some space. The editor has written the database backup code before and will not repeat it here. The official download address of Pclzip is: http://www.phpconcept.net/pclzip/pclzip-downloads (the latest version 2-8-2).
Download address of this website.

Look for 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("备份成功&&压缩成功");
}else
{
die("Error : ".$archive->errorInfo(true));
$this->error("备份失败");
}

Copy after login

And delete the original if judgment in the original DatabaseAction.class.php

Readers who are interested in more thinkPHP related content can Check out the special topics on this site: "Summary of zip file operation and compression techniques in PHP", "Summary of PHP file operation", "Introduction to ThinkPHP tutorial", "Summary of common methods of ThinkPHP", "Basic tutorial for entry into smarty templates" and "Summary of PHP template technology" .

I hope this article will help you design PHP programs based on the ThinkPHP framework.

The above introduces thinkPHP's method of using pclzip packaging to back up mysql database, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template