The following articles mainly introduce MySQL Backup Based on table backup. This article uses the actual application code to introduce MySQL Backup Based on table backup, the following describes the main content of the article, hoping to help you in this aspect.
- <?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;
- }
The above content is related to MySQL backup-based on the introduction of table backup, I hope you will have some gains.
The above content is related to MySQL backup-based on the introduction of table backup, I hope you will have some gains.