根據(jù)Mysql表備份
作者:佚名
Mysql數(shù)據(jù)庫的備份方法是每一個DBA都應(yīng)該掌握的,下面為您介紹的備份方法是根據(jù)表進(jìn)行備份的,如果您感興趣的話,不妨一看。
Mysql數(shù)據(jù)庫有多種的備份方法,下面為您介紹的方法是根據(jù)Mysql表備份,該方法供您參考,希望對您學(xué)習(xí)Mysql表備份數(shù)據(jù)庫方面能有所幫助。
- <?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;
- }
- ?>
【編輯推薦】
責(zé)任編輯:段燃
來源:
互聯(lián)網(wǎng)