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 ;}