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.
- <?php
- function datatosql($table)
- {
- global $db;
- $tabledump = "DROP TABLE IF EXISTS $table;\n";
- $createtable = $db->query("SHOW CREATE TABLE $table");
- $create = $db->fetch_array($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_array($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;
- }
- ?>
MySQL Show statement usage
Seven Mysql table types
MySQL connection query Overview
Optimization instance for MySQL random Query
MySQL sorting usage