Back up data based on Mysql tables

Source: Internet
Author: User

The Mysql database has multiple backup methods. The following describes how to back up data based on the Mysql table. This method is for your reference. I hope you can learn more about Mysql table backup database.

 
 
  1. <?php 
  2. function datatosql($table)       
  3. {      
  4.     global $db;      
  5.     $tabledump = "DROP TABLE IF EXISTS $table;\n";      
  6.     $createtable = $db->query("SHOW CREATE TABLE $table");      
  7.     $create = $db->fetch_array($createtable);      
  8.     $tabledump .= $create[1].";\n\n";      
  9.      
  10.     $rows = $db->query("SELECT * FROM $table");      
  11.     $numfields = $db->num_fields($rows);      
  12.     $numrows = $db->num_rows($rows);      
  13.     while ($row = $db->fetch_array($rows)){      
  14.         $comma = "";      
  15.         $tabledump .= "INSERT INTO $table VALUES(";      
  16.         for($i = 0; $i < $numfields; $i++)       
  17.         {      
  18.         $tabledump .= $comma."'".mysql_escape_string($row[$i])."'";      
  19.         $comma = ",";      
  20.         }      
  21.         $tabledump .= ");\n";      
  22.     }      
  23.     $tabledump .= "\n";      
  24.      
  25.     return $tabledump;      
  26. }     
  27. ?> 

MySQL Show statement usage

Seven Mysql table types

MySQL connection query Overview

Optimization instance for MySQL random Query

MySQL sorting usage

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.