数据备份 - 如何用ThinkPHP开发一个数据库备份功能

WBOY
Release: 2016-06-06 20:42:36
Original
1346 people have browsed it

如何用ThinkPHP开发一个数据库备份功能

就是各大CMS的数据库备份还原功能如何实现

回复内容:

如何用ThinkPHP开发一个数据库备份功能

就是各大CMS的数据库备份还原功能如何实现

从开源博客系统Emlog里找了一段:
https://github.com/emlog/emlog/blob/master/src/admin/data.php

<code>/**
 * 备份数据库结构和所有数据
 *
 * @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 </code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template