Mysql數據庫有多種的備份方法,下面為您介紹的方法是根據Mysql表備份,該方法供您參考,希望對您學習MySQL表備份數據庫方面能有所幫助。
- <?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;
- }
- ?>