add new method createDump()

This commit is contained in:
Uwe Steinmann 2015-12-09 18:24:31 +01:00
parent 56683a6104
commit d105fa5155

View File

@ -2269,5 +2269,39 @@ class SeedDMS_Core_DMS {
$this->callbacks[$name] = array($func, $params);
} /* }}} */
/**
* Create an sql dump of the complete database
*
* @param string $filename name of dump file
*/
function createDump($filename) { /* {{{ */
$h = fopen($filename, "w");
if(!$h)
return false;
$tables = $this->db->TableList('TABLES');
foreach($tables as $table) {
$query = "SELECT * FROM `".$table."`";
$records = $this->db->getResultArray($query);
fwrite($h,"\n-- TABLE: ".$table."--\n\n");
foreach($records as $record) {
$values="";
$i = 1;
foreach ($record as $column) {
if (is_numeric($column)) $values .= $column;
else $values .= $this->db->qstr($column);
if ($i<(count($record))) $values .= ",";
$i++;
}
fwrite($h, "INSERT INTO `".$table."` VALUES (".$values.");\n");
}
}
fclose($h);
return true;
} /* }}} */
}
?>