Share a php class library for MYSQL backup-PHP source code

Source: Internet
Author: User
Tags mysql backup
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 )!

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.