0
0
function backup($bakfile = null, $tables = array())
{
if (empty($bakfile)) {
$bakfile = $this->dbname . date("Ymdhis") . '.sql';
} elseif (is_dir($bakfile)) {
if (preg_match('//$/', $bakfile)) {
$bakfile = $bakfile . $this->dbname . date("Ymdhis") . '.sql';
} else {
$bakfile = $bakfile . '/' . $this->dbname . date("Ymdhis") . '.sql';
}
}
if (!$tables) {
$this->query("SHOW TABLES");
while ($row = mysql_fetch_row($this->queryID)) {
$tables[] = $row[0];
}
} else {
foreach ($tables as $k => $v) {
$tables[$k] = $this->tablePrefix . $v;
}
}
if ($fp = fopen($bakfile, 'wb')) {
if ($this->dbcharset) {
fwrite($fp, "SET NAMES " . $this->dbcharset . ";nn");
}
foreach ($tables as $table) {
$this->dumpTable($table, $fp);
fwrite($fp, "n");
}//foreach
fclose($fp);
return true;
} else {
return false;
}//if
}
//私有方法 导出表格
function dumpTable($fullTableName, $fp)
{
//备份表结构
fwrite($fp, "-- n-- {$fullTableName}n-- n");
$row = $this->findBySql("SHOW CREATE TABLE `{$fullTableName}`");
fwrite($fp, $row['Create Table'] . ";nn" );
//备份表库数据
$this->query("SELECT * FROM `{$fullTableName}`");
while ($row = mysql_fetch_assoc($this->queryID)) {
foreach ($row as $k=>$v) {
$row[$k] = "'" . $this->qstr($v) . "'" ;
}
$sql = "INSERT INTO `$fullTableName` VALUES (" . join(",", $row) . ");n";
fwrite($fp, $sql);
}
mysql_free_result($this->queryID);
fwrite($fp, "n");
}
//恢复数据库文件
function restore($bakfile)
{
if ($fp = fopen($bakfile, 'r')) {
$sql = '';
while (!feof($fp)) {
$line = fgets($fp);
if (strpos($line,'--')!==0)
{
$sql .= $line;
//pp($sql);
}
if (preg_match('/;s*$/', $sql)) {
$this->query($sql);
$sql = '';
}
}
fclose($fp);
return true;
} else {
return false;
}
}
本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门AI工具
相关专题
2026赚钱平台入口大全
2026年最新赚钱平台入口汇总,涵盖任务众包、内容创作、电商运营、技能变现等多类正规渠道,助你轻松开启副业增收之路。阅读专题下面的文章了解更多详细内容。
76
2026.01.31
无需付费的漫画app大全
想找真正免费又无套路的漫画App?本合集精选多款永久免费、资源丰富、无广告干扰的优质漫画应用,涵盖国漫、日漫、韩漫及经典老番,满足各类阅读需求。阅读专题下面的文章了解更多详细内容。
67
2026.01.31
漫画免费在线观看地址大全
想找免费又资源丰富的漫画网站?本合集精选2025-2026年热门平台,涵盖国漫、日漫、韩漫等多类型作品,支持高清流畅阅读与离线缓存。阅读专题下面的文章了解更多详细内容。
19
2026.01.31
热门下载







