Data backup-how to use ThinkPHP to develop a database backup function

Source: Internet
Author: User
How to Use ThinkPHP to develop a database backup function is how to use ThinkPHP to develop a database backup function for the database backup and restoration functions of various major CMS databases

Is how the database backup and restoration functions of major CMS are implemented

Reply content:

How to Use ThinkPHP to develop a database backup function

Is how the database backup and restoration functions of major CMS are implemented

I found a section from the open-source blog system Emlog:
Https://github.com/emlog/emlog/blob/master/src/admin/data.php

/*** Back up the database structure and all data ** @ param string $ table database table name * @ return string */function dataBak ($ table) {$ DB = MySql :: getInstance (); $ SQL = "DROP TABLE IF EXISTS $ table; \ n"; $ createtable = $ DB-> query ("SHOW CREATE TABLE $ table "); $ create = $ DB-> fetch_row ($ createtable); $ SQL. = $ create [1]. "; \ n"; $ rows = $ DB-> query ("SELECT * FROM $ table"); $ numfields = $ DB-> num_fields ($ rows ); $ numrows = $ DB-> num_rows ($ rows); while ($ row = $ DB-> fetch_row ($ rows) {$ comma = ""; $ SQL. = "insert into $ table VALUES ("; for ($ I = 0; $ I <$ numfields; $ I ++) {$ SQL. = $ comma. "'". mysql_escape_string ($ row [$ I]). "'"; $ comma = "," ;}$ SQL. = "); \ n" ;}$ SQL. = "\ n"; return $ SQL ;}

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.