Data backup-How to develop a database backup function with thinkphp

Source: Internet
Author: User
How to develop a database backup function with thinkphp

is the database backup and restore function of the major CMS how to implement

Reply content:

How to develop a database backup function with thinkphp

is the database backup and restore function of the major CMS how to implement

From the Open Source blog system Emlog found a paragraph:
https://github.com/emlog/emlog/blob/master/src/admin/data.php

/** * 备份数据库结构和所有数据 * * @param string $table 数据库表名 * @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\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;}
  • 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.