日期:2013-04-26  浏览次数:20406 次

<?php
/*
This TextData Class txtTbl writen by ridge.jiang mostone@hotmail.com and finished in 2003.01.01
Your can copy and use it without agreedment,It's free. But you can't use it for busness using.
You are also wellcome to modify this code in your mind. Thank for your work and tell me.

This class is for small information database so like classmater databse,they are less than 300 recorders.
If your want store and opreat more than 300 recorders,It's recommandly to use SQL server.

Your may acess the Instance of this Class with bellow function,there recommandly Do NOT use
inner var and function,because that's unsafe.
create()
drop()
open()
close()
eof()
bof()
prev()
next()
first()
end()

fieldsCount()
getValue()
setValue()

display()
location()

recNO()
recCount()

del()
append()

*/
define ("tblPath",".\\");
define ("exten",".php");
define ("fileHead","<? echo \"You are wellcome!\"?".">This file only for class txtTbl");
class txtTbl {
  var $innerName="";  //数据库名称
  var $innerCount;  //数据库记录数目
  var $innerFields;  //数据库字段列表数组
  var $inner_F_Count; //数据库字段数目
  var $fullName;  //完整的文件名
  var $isModify = false;  //当前记录是否被修改
  var $fileModify = false;  //数据库是否被修改
  var $innerRecorders;  //数据库记录数组
  var $curLine;  //当前记录号
  var $curArray;  //当前行数组
  var $stringDel;  //保存被删除记录
  var $sprt1;  //数据库记录间的分隔符
  var $sprt2;  //数据库字段间的分隔符
  var $innerBof = true;
  var $innerEof = false;

 

  function create($tblName,$fields,$sprt1="<---txtTbl--->\n",$sprt2="<---txtTbl--->"){
 if (empty($tblName)){
  echo "The textDateBase file name not appoint.";
  return false;
 }
 $fullName = tblPath.$tblName.exten;
    if (file_exists($fullName)){
  echo "The textDateBase file is already exist.";
  return false;
 }
    if(empty($fields)){
  echo "The fields list Array is invalid.";
  return false;
 }
 $cont = implode($sprt2,$fields);
 $cont = fileHead."\n".$cont;
 $fp = fopen($fullName,"w");
    fwrite($fp,$cont);
 fclose($fp);
 return true;
  }

  function drop($tblName,$sprt1="<---txtTbl--->\n",$sprt2="<---txtTbl--->"){
 if (empty($tblName)){
  echo "The textDateBase file name not proveid.";
  return false;
 }
 if (!empty($this->innerName)){
  echo "Current file not closed,Please close it and try again.";
  return false;
 }
 $fullName = tblPath.$tblName.exten;
    if (!file_exists($fullName)){
  echo "The textDateBase file not exist.";
  return false;
 }
 $fp = fopen($fullName,"r");
 if (!feof($fp)){
  $readFromFile = fgets($fp);
 }
 if ($readFromFile!=fileHead."\n"){
  fclose($fp);
  echo "not a valid textDataBase file.(the head is invalid.)"."\n";
  return false;
 }
 $readFromFile = "";
 if (!feof($fp)) $readFromFile.= fgets($fp);
 fclose($fp);
 $readFromFile = trim($readFromFile);
 if (empty($readFromFile)){
  echo "not a valid textDataBase file.(can't find fields define.)";
  return false;