Share a php MYSQL backup class library and a phpmysql backup class library

Source: Internet
Author: User
Tags php mysql mysql backup

Share a php MYSQL backup class library and a phpmysql backup class library

I just want to study how to back up the database and share a php class library for MYSQL backup.

<? Php/******* back up the database structure ******* // ***** it is just necessary to study how to back up the database, share a php class library for MYSQL backup ******** // function name: table2sql () function: Convert the table structure into SQL function parameters: $ table: Return Value of the table name to be extracted: return the extracted result. Author of the SQL set function: heiyeluren */function table2sql ($ 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"; return $ tab Ledump;}/******* back up the database structure and all data ****** // function name: data2sql () function: convert the table structure and data into SQL function parameters: $ table: Return Value of the table name to be extracted: return the extracted result. Author of the SQL set function: 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;}?>

Http://php.662p.com/thread-560-1-1.html

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.