Answers
从开源博客系统Emlog里找了一段:
https://github.com/emlog/emlog/blob/master/src/admin/data.php
/**
* 备份数据库结构和所有数据
*
* @param string $table 数据库表名
* @return string
*/
function dataBak($table){
$DB = MySql::getInstance();
$sql = "DROP TABLE IF EXISTS $table;\n";
$createtable = $DB->query("SHOW CREATE TABLE $table");
$create = $DB->fetch_row($createtable);
$sql .= $create[1].";\n\n";
$rows = $DB->query("SELECT * FROM $table");
$numfields = $DB->num_fields($rows);
$numrows = $DB->num_rows($rows);
while ($row = $DB->fetch_row($rows)){
$comma = "";
$sql .= "INSERT INTO $table VALUES(";
for ($i = 0; $i < $numfields; $i++){
$sql .= $comma."'".mysql_escape_string($row[$i])."'";
$comma = ",";
}
$sql .= ");\n";
}
$sql .= "\n";
return $sql;
}
傲娇的字幕君
answered 10 years, 3 months ago