php 文本数据库类,php文本数据库操作类 代码(2)

$execute .= '$row[]=trim(fread($fp,'.$values[$i].'));';

if($id <= $i){

$execute .= 'fseek($fp,'.($length-$sum).',SEEK_CUR);';

break;

}

}

$execute .= 'if($type==\'1\' && '.$query.'){fseek($fp,'.(-1*($length+1)).',SEEK_CUR);';

eval($execute.'fwrite($fp,\'0\');$rows++;seek($fp,'.$length.',SEEK_CUR);}}');

if($dp = dir($this->dataBase."/".$this->dataCache)){

while($file = $db->read())if(strstr($file,"tdc"))unlink($this->dataBase."/".$this->dataCache."/$file");

$dp->close();

}

fclose($fp);

return $rows;

}

}

function clean($tableName){

if(!$fp = fopen($this->dataBase."/".$tableName.".tdb","r")){

$this->dataError = "数据表打开失败";

return false;

}else if(!strstr(fread($fp,20),"TDB")){

$this->dataError = "数据库文件被破坏或者格式错误";

fclose($fp);

return false;

}else{

fseek($fp,20,SEEK_CUR);

for($i=0,$length=0,$result="1",$head=array(),$tmp=explode(';',trim(fread($fp,160)));$i

list($key,$value) = explode(':',$tmp[$i]);

$head[$key] = $value;

$length += $value;

}

if(rewind($this->fp) && $fp1 = fopen($this->dataBase."/".$tableName.".tdb.tmp","w")){

fwrite($fp1,fread($fp,200));

while(strlen($tmp = fread($fp,$length+1))){

($tmp{0} == "1") && fwrite($fp1,$tmp);

}

fclose($fp1);

fclose($fp);

unlink($this->dataBase."/".$tableName.".tdb");

rename($this->dataBase."/".$tableName.".tdb.tmp",$this->dataBase."/".$tableName.".tdb");

if($dp = dir($this->dataBase."/".$this->dataCache)){

while($file = $db->read())if(strstr($file,"tdc"))unlink($this->dataBase."/".$this->dataCache."/$file");

$dp->close();

}

return true;

}else{

fclose($fp);

return false;

}

}

}

function create($tableName,$args){

if(file_exists($this->dataBase."/".$tableName.".tdb")){

$this->dataError = "数据表 $table 已经存在";

}else if($fp = fopen($this->dataBase."/".$tableName.".tdb","w")){

fwrite($fp,str_pad("TDB1.0",20));

fwrite($fp,pack("V*",0,0,0,count($args),array_sum($args)));

$tmp = "";

foreach($args AS $key=>$value)$tmp .= "$key:$value;";

fwrite($fp,str_pad($tmp,160));

fclose($fp);

return true;

}else{

$this->dataError = "数据表建立失败";

return false;

}

}

}

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值