帝国cms自定义函数,投稿自动分表:
<?php
//---------------------------投稿自动分表函数--------------------------
function zdtgfb($tid,$size)
{ global $empire,$dbtbpre;
$tb=$empire->fetch1("select tbname,datatbs,deftb from {$dbtbpre}enewstable where tid='$tid'");
$tbname=$tb[tbname];
$stbarr=explode(",",$tb[datatbs]);
$newstb=0;
for($i=0;$i<count($stbarr);$i++)
{ if($stbarr[$i])
{ $ftb=$empire->fetch1("SHOW TABLE STATUS LIKE '{$dbtbpre}ecms_".$tbname."_data_".$stbarr[$i]."';");
$ftbsize=($ftb[Data_length]+$ftb[Index_length])/pow(1024,2);
if($ftbsize<$size)
{ if($tb[deftb]!=$stbarr[$i])
{ $empire->query("update {$dbtbpre}enewstable set deftb=".$stbarr[$i]." where tid='$tid'");}
$newstb=$stbarr[$i];
break;
}
$maxstb=$stbarr[$i];
}
}
if(!$newstb)
{ $maxstb++;
$odtb=$dbtbpre."ecms_".$tbname."_data_1";
$dtb=$dbtbpre."ecms_".$tbname."_data_".$maxstb;
CopyEcmsTb($odtb,$dtb);
$empire->query("update {$dbtbpre}enewstable set datatbs='".$tb[datatbs].$maxstb.",',deftb=$maxstb where tid='$tid'");
$newstb=$maxstb;
}
GetConfig(1);
return $newstb;
}
?>