📄 functions.php
字号:
{
$status_r=Ebak_GetTotal($b_dbname,$btb[$t]);
$num=$status_r['Rows'];
}
}
else
{
$num=(int)$alltotal;
}
}
//备份数据库结构
if($b_stru&&empty($s))
{
$dumpsql.=Ebak_Returnstru($btb[$t],$b_strufour);
}
//取得字段数
if(empty($fnum))
{
$return_fr=Ebak_ReturnTbfield($b_dbname,$btb[$t],$b_autofield);
$fieldnum=$return_fr['num'];
$noautof=$return_fr['autof'];
$auf=$return_fr['auf'];
}
else
{
$fieldnum=$fnum;
$noautof=$thenof;
}
//自动识别自增项
$aufval=(int)$aufval;
if($b_autoauf==1&&$auf)
{
$sql=$empire->query("select * from `".$btb[$t]."` where ".$auf.">".$aufval." order by ".$auf." limit $b_bakline");
}
else
{
$sql=$empire->query("select * from `".$btb[$t]."` limit $s,$b_bakline");
}
//完整插入
$inf='';
if($b_beover==1)
{
$inf='('.Ebak_ReturnInTbfield($b_dbname,$btb[$t]).')';
}
$b=0;
while($r=$empire->fetch($sql))
{
if($auf)
{
$lastaufval=$r[$auf];
}
$b=1;
$s++;
$dumpsql.="E_D(\"".$b_insertf." into `".$btb[$t]."`".$inf." values(";
$first=1;
for($i=0;$i<$fieldnum;$i++)
{
//首字段
if(empty($first))
{
$dumpsql.=",";
}
else
{
$first=0;
}
$myi=$i+1;
if(!isset($r[$i])||strstr($noautof,",".$myi.","))
{
$dumpsql.="NULL";
}
else
{
$dumpsql.="'".escape_str($r[$i])."'";
}
}
$dumpsql.=");\");\r\n";
}
if(empty($b))
{
//最后一个备份
if(empty($p))
{
$p++;
$sfile=$path."/".$btb[$t]."_".$p.".php";
$dumpsql=$header.$dumpsql.$footer;
WriteFiletext_n($sfile,$dumpsql);
}
Ebak_RepFilenum($p,$btb[$t],$path);
$t++;
$empire->free($sql);
//进入下一个表
//echo $btb[$t-1].$fun_r['OneTableBakSuccess']."<script>self.location.href='phome.php?phome=BakExeT&s=0&p=0&t=$t&mypath=$mypath&stime=$stime';</script>";
echo"<meta http-equiv=\"refresh\" content=\"".$waitbaktime.";url=phome.php?phome=BakExeT&s=0&p=0&t=$t&mypath=$mypath&stime=$stime&waitbaktime=$waitbaktime\">".$btb[$t-1].$fun_r['OneTableBakSuccess'];
exit();
}
//进入下一组
$p++;
$sfile=$path."/".$btb[$t]."_".$p.".php";
$dumpsql=$header.$dumpsql.$footer;
WriteFiletext_n($sfile,$dumpsql);
$empire->free($sql);
//echo $fun_r['BakOneDataSuccess'].Ebak_EchoBakSt($btb[$t],$count,$t,$num,$s)."<script>self.location.href='phome.php?phome=BakExeT&s=$s&p=$p&t=$t&mypath=$mypath&alltotal=$num&thenof=$noautof&fieldnum=$fieldnum&auf=$auf&aufval=$lastaufval&stime=$stime';</script>";
echo"<meta http-equiv=\"refresh\" content=\"".$waitbaktime.";url=phome.php?phome=BakExeT&s=$s&p=$p&t=$t&mypath=$mypath&alltotal=$num&thenof=$noautof&fieldnum=$fieldnum&auf=$auf&aufval=$lastaufval&stime=$stime&waitbaktime=$waitbaktime&collation=$collation\">".$fun_r['BakOneDataSuccess'].Ebak_EchoBakSt($btb[$t],$count,$t,$num,$s);
exit();
}
//输出备份进度条
function Ebak_EchoBakSt($tbname,$tbnum,$tb,$rnum,$r){
$table=($tb+1).'/'.$tbnum;
$record=$r;
if($rnum!=-1)
{
$record=$r.'/'.$rnum;
}
?>
<br><br>
<table width="90%" border="0" align="center" cellpadding="3" cellspacing="1">
<tr><td height="25">Table Name : <b><?=$tbname?></b></td></tr>
<tr><td height="25">Table : <b><?=$table?></b></td></tr>
<tr><td height="25">Record : <b><?=$record?></b></td></tr>
</table><br><br>
<?
}
//输出恢复进度条
function Ebak_EchoReDataSt($tbname,$tbnum,$tb,$pnum,$p){
$table=($tb+1).'/'.$tbnum;
$record=$p.'/'.$pnum;
?>
<br><br>
<table width="90%" border="0" align="center" cellpadding="3" cellspacing="1">
<tr><td height="25">Table Name : <b><?=$tbname?></b></td></tr>
<tr><td height="25">Table : <b><?=$table?></b></td></tr>
<tr><td height="25">File : <b><?=$record?></b></td></tr>
</table><br><br>
<?
}
//取得表记录数
function Ebak_GetTotal($dbname,$tbname){
global $empire;
/*
$tr=$empire->fetch1("select count(*) AS total from ".$btb[$t]);
$num=$tr[total];
*/
$tr=$empire->fetch1("SHOW TABLE STATUS LIKE '".$tbname."';");
return $tr;
}
//返回字符集set
function Ebak_GetSetChar($char){
global $empire;
if(empty($char))
{
return '';
}
$r=$empire->fetch1("SHOW COLLATION LIKE '".$char."';");
return $r['Charset'];
}
//返回表字段信息
function Ebak_ReturnTbfield($dbname,$tbname,$autofield){
global $empire;
$sql=$empire->query("SHOW FIELDS FROM `".$tbname."`");
$i=0;//字段数
$autof=",";//去除自增字段列表
$f='';//自增字段名
while($r=$empire->fetch($sql))
{
$i++;
if(strstr($autofield,",".$tbname.".".$r[Field].","))
{
$autof.=$i.",";
}
if($r['Extra']=='auto_increment')
{
$f=$r['Field'];
}
}
$return_r['num']=$i;
$return_r['autof']=$autof;
$return_r['auf']=$f;
return $return_r;
}
//返回插入字段
function Ebak_ReturnInTbfield($dbname,$tbname){
global $empire;
$sql=$empire->query("SHOW FIELDS FROM `".$tbname."`");
$f='';
$dh='';
while($r=$empire->fetch($sql))
{
if($f)
{
$dh=',';
}
$f.=$dh.'`'.$r['Field'].'`';
}
return $f;
}
//替换文件数
function Ebak_RepFilenum($p,$table,$path){
if(empty($p))
{$p=0;}
$file=$path."/config.php";
$text=ReadFiletext($file);
$rep1="\$tb[".$table."]=0;";
$rep2="\$tb[".$table."]=".$p.";";
$text=str_replace($rep1,$rep2,$text);
WriteFiletext_n($file,$text);
}
//执行SQL
function E_D($sql){
global $empire;
$empire->query($sql);
}
//建立表
function E_C($sql){
global $empire;
$empire->query(Ebak_AddDbchar($sql));
}
//转为Mysql4.0格式
function Ebak_ToMysqlFour($query){
$exp="ENGINE=";
if(!strstr($query,$exp))
{
return $query;
}
$exp1=" ";
$r=explode($exp,$query);
//取得表类型
$r1=explode($exp1,$r[1]);
$returnquery=$r[0]."TYPE=".$r1[0];
return $returnquery;
}
//---------------------返回数据库结构
function Ebak_Returnstru($table,$strufour){
global $empire;
$dumpsql.="E_D(\"DROP TABLE IF EXISTS `".$table."`;\");\r\n";
//设置引号
$usql=$empire->query("SET SQL_QUOTE_SHOW_CREATE=1;");
//数据表结构
$r=$empire->fetch1("SHOW CREATE TABLE `$table`;");
$create=str_replace("\"","\\\"",$r[1]);
//转为4.0格式
if($strufour)
{
$create=Ebak_ToMysqlFour($create);
}
$dumpsql.="E_C(\"".$create."\");\r\n";
return $dumpsql;
}
//返回设置编码
function Ebak_ReturnSetNames($char){
if(empty($char))
{
return '';
}
$dumpsql="DoSetDbChar('".$char."');\r\n";
return $dumpsql;
}
//去除字段中的编码
function Ebak_ReplaceFieldChar($sql){
global $phome_use_dbver;
if($phome_use_dbver=='4.0'&&strstr($sql,' character set '))
{
$preg_str="/ character set (.+?) collate (.+?) /is";
$sql=preg_replace($preg_str,' ',$sql);
}
return $sql;
}
//加编码
function Ebak_AddDbchar($sql){
global $phome_use_dbver,$phome_db_char,$b_dbchar;
//加编码
if($phome_use_dbver>='4.1'&&!strstr($sql,'ENGINE=')&&($phome_db_char||$b_dbchar)&&$b_dbchar!='auto')
{
$dbcharset=$b_dbchar?$b_dbchar:$phome_db_char;
$sql=Ebak_DoCreateTable($sql,$phome_use_dbver,$dbcharset);
}
elseif($phome_use_dbver=='4.0'&&strstr($sql,'ENGINE='))
{
$sql=Ebak_ToMysqlFour($sql);
}
//去除字段中的编码
$sql=Ebak_ReplaceFieldChar($sql);
return $sql;
}
//建表
function Ebak_DoCreateTable($sql,$mysqlver,$dbcharset){
$type=strtoupper(preg_replace("/^\s*CREATE TABLE\s+.+\s+\(.+?\).*(ENGINE|TYPE)\s*=\s*([a-z]+?).*$/isU","\\2",$sql));
$type=in_array($type,array('MYISAM','HEAP'))?$type:'MYISAM';
return preg_replace("/^\s*(CREATE TABLE\s+.+\s+\(.+?\)).*$/isU","\\1",$sql).
($mysqlver>='4.1'?" ENGINE=$type DEFAULT CHARSET=$dbcharset":" TYPE=$type");
}
//返回版权信息
function Ebak_ReturnVer()
{
$string="
/*
SoftName : EmpireBak
Author : wm_chief
Copyright: Powered by www.phome.net
*/
";
return $string;
}
//转换大小
function Ebak_ChangeSize($size){
if($size<1024)
{
$str=$size." B";
}
elseif($size<1024*1024)
{
$str=round($size/1024,2)." KB";
}
elseif($size<1024*1024*1024)
{
$str=round($size/(1024*1024),2)." MB";
}
else
{
$str=round($size/(1024*1024*1024),2)." GB";
}
return $str;
}
//导入数据
function Ebak_ReData($add,$mypath,$userid,$username){
global $empire,$public_r;
//验证权限
CheckLevel($userid,$username,$classid,"dbdata");
if(empty($mypath)||empty($add[mydbname]))
{printerror("EmptyDbnamePath","history.go(-1)");}
$bakpath=$public_r['bakdbpath'];
$path=$bakpath."/".$mypath;
if(!file_exists($path))
{
printerror("DbPathNotExist","history.go(-1)");
}
@include($path."/config.php");
if(empty($b_table))
{
printerror("BakCsError","history.go(-1)");
}
$waitbaktime=(int)$add['waitbaktime'];
$btb=explode(",",$b_table);
$nfile=$path."/".$btb[0]."_1.php?t=0&p=0&mydbname=$add[mydbname]&mypath=$mypath&waitbaktime=$waitbaktime";
Header("Location:$nfile");
exit();
}
//删除备份目录
function Ebak_DelBakpath($path,$userid,$username){
global $public_r;
//验证权限
CheckLevel($userid,$username,$classid,"dbdata");
if(strstr($path,".."))
{printerror("NotChangeDelPath","history.go(-1)");}
if(!trim($path))
{printerror("NotChangeDelPath","history.go(-1)");}
$bakpath=$public_r['bakdbpath'];
$delpath=$bakpath."/".$path;
if(!file_exists($delpath))
{
printerror("ThisPathNotExist","history.go(-1)");
}
@include_once("../../class/delpath.php");
$delpath=DelPath($delpath);
//操作日志
insert_dolog("path=".$path);
printerror("DelPathSuccess","ChangePath.php?change=".$_GET['change']);
}
//打包目录
function ZipFile($path,$zipname){
global $public_r;
$bakpath=$public_r['bakdbpath'];
$bakzippath=$public_r['bakdbzip'];
@include("../../class/phpzip.inc.php");
$z=new PHPZip(); //新建立一个zip的类
$z->Zip($bakpath."/".$path,$bakzippath."/".$zipname); //添加指定目录
}
//删除压缩包
function Ebak_DelZip($file,$userid,$username){
global $public_r;
//验证权限
CheckLevel($userid,$username,$classid,"dbdata");
if(strstr($file,".."))
{printerror("FileNotExist","history.go(-1)");}
if(empty($file))
{
printerror("FileNotExist","history.go(-1)");
}
$bakzippath=$public_r['bakdbzip'];
$filename=$bakzippath."/".$file;
if(!file_exists($filename))
{
printerror("FileNotExist","history.go(-1)");
}
DelFiletext($filename);
//操作日志
insert_dolog("file=".$file);
printerror("DelZipFileSuccess","history.go(-1)");
}
//压缩目录
function Ebak_Dozip($path,$userid,$username){
global $public_r;
//验证权限
CheckLevel($userid,$username,$classid,"dbdata");
if(strstr($path,".."))
{printerror("ThisPathNotExist","history.go(-1)");}
if(empty($path))
{
printerror("ThisPathNotExist","history.go(-1)");
}
$bakpath=$public_r['bakdbpath'];
$bakzippath=$public_r['bakdbzip'];
$mypath=$bakpath."/".$path;
if(!file_exists($mypath))
{
printerror("ThisPathNotExist","history.go(-1)");
}
$zipname=$path.".zip";
ZipFile($path,$zipname);
echo"<script>self.location.href='DownZip.php?f=$zipname&p=$path';</script>";
}
//转向恢复页面
function Ebak_PathGotoRedata($path,$userid,$username){
global $public_r;
//验证权限
CheckLevel($userid,$username,$classid,"dbdata");
if(strstr($path,".."))
{printerror("NotChangeDelPath","history.go(-1)");}
if(!trim($path))
{printerror("NotChangeDelPath","history.go(-1)");}
$bakpath=$public_r['bakdbpath'];
$repath=$bakpath."/".$path;
if(!file_exists($repath))
{
printerror("ThisPathNotExist","history.go(-1)");
}
@include $repath.'/config.php';
Header("Location:ReData.php?mydbname=$b_dbname&mypath=$path");
exit();
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -