Share a php class library for MYSQL backup
Share a php class library for MYSQL backup
I just want to study how to back up the database and share a php class library for MYSQL backup.
Query ("show create table $ table"); $ create = $ db-> fetch_row ($ createtable); $ tabledump. = $ create [1]. "; \ n"; return $ tabledump;}/******* back up the database structure and all data ****** // * function name: data2sql () function: converts the table structure and data into SQL function parameters: $ table: return value of the table name to be extracted: return the extracted result, SQL collection function author: heiyeluren */function data2sql ($ table) {global $ db; $ tabledump = "DROP TABLE IF EXISTS $ table; \ n "; $ createtable = $ db-> query ("show create table $ table "); $ Create = $ db-> fetch_row ($ createtable); $ tabledump. = $ 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 = ""; $ tabledump. = "insert into $ table VALUES ("; for ($ I = 0; $ I <$ numfields; $ I ++) {$ tabledump. = $ comma. "'". mysql_escape_string ($ row [$ I]). "'"; $ comma = "," ;}$ Tabledump. = "); \ n" ;}$ tabledump. = "\ n"; return $ tabledump ;}?>
The above is to share the content of a class library for implementing MYSQL backup in php. For more information, see PHP Chinese network (www.php1.cn )!