Share a PHP class library that implements MySQL backup

Source: Internet
Author: User
Tags php class mysql backup

Just want to study how to back up the database, share a PHP implementation of MySQL backup class library

<?php/****** backing up the database structure ******//**** just want to study how to back up the database, share a PHP implementation of MySQL backup class library ********//* Function name: Table2sql () function function: Put the table to a SQL function parameter: $table: Returns the value of the table name to extract: Returns the extracted result, SQL aggregate 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\n ";      return $tabledump;       /****** back up the database structure and all data ******//* Function name: Data2sql () function: Convert table structure and data into SQL function parameters: $table: The name of the table to extract         Return value: Returns the extracted result, SQL aggregate 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\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; }?>

Detailed Description: http://php.662p.com/thread-560-1-1.html

Share a PHP class library that implements MySQL backup

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.