PHP文本数据表类_PHP
P>刚学习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="\n",$sprt2=""){
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="\n",$sprt2=""){
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;
}
$cont = fileHead."\n".$readFromFile;
$fp = fopen($fullName,"w");
fwrite($fp,$cont);
fclose($fp);
return true;
}
function open($tblName,$sprt1="\n",$sprt2=""){
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;
}
$this->fullName = tblPath.$tblName.exten;
if (!file_exists($this->fullName)){
echo "The textDateBase file not exist.";
return false;
}
$fp = fopen($this->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 = "";
while (!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;
}
$this->innerRecorders = explode($sprt1,$readFromFile);
$this->innerCount = count($this->innerRecorders) - 1;
$this->innerFields = explode($sprt2,$this->innerRecorders[0]);
$this->innerFieldsCount = count($this->innerFields);
$this->innerName = $tblName;
$this->sprt1 = $sprt1;
$this->sprt2 = $sprt2;
if ($this->innerCount==0){
$this->curLine = 0;
$this->innerEof = true;
}else{
$this->curLine = 1;
// if ($this->innerCount==1) $this->innerEof = true;
if (!$this->initRec()) return false;
}
return true;
}
function close(){
if (empty($this->innerName)) return true;
//save modify
$isModify= false;
if ($this->isModify){
$this->saveModify();
$isModify= true;
}
if(isset($this->stringDel)){
$isModify= true;
$delNo= explode(",",$this->stringDel);
foreach($delNo as $no){
$no= (integer) $no;
unset($this->innerRecorders[$no]);
}
}
if ($isModify||$this->fileModify){
$recorders= implode($this->sprt1,$this->innerRecorders);
$recorders= fileHead."\n".$recorders;
$fp = fopen($this->fullName,"w");
fwrite($fp,$recorders);
fclose($fp);
}
$this->innerName="";
unset($this->innerRecorders);
unset($this->curArray);
}
function next(){
if ((!$this->innerEof)&&(!empty($this->innerName))){
if($this->curLine==$this->innerCount){
$this->innerEof = true;
return true;
}
$this->saveModify();
$this->curLine++;
if ($this->innerBof) $this->innerBof = false;
$this->initRec();
}
return false;
}
function prev(){
if ((!$this->innerBof)&&(!empty($this->innerName))){
$this->saveModify();
$this->curLine--;
if ($this->curLine == 1)
$this->innerBof = true;
if ($this->innerEof) $this->innerEof = false;
$this->initRec();
}
}
function first(){
if ($this->innerBof||empty($this->innerName))
return false;
$this->saveModify();
$this->curLine = 1;
$this->innerBof= true;
$this->innerEof = false;
$this->initRec();
}
function end(){
if ($this->innerEof||empty($this->innerName))
return false;
$this->saveModify();
$this->curLine = $this->innerCount;
$this->innerEof= true;
$this->innerBof = false;
$this->initRec();
}
function eof(){
if (empty($this->innerName)){
return false;
}else return $this->innerEof;
}
function bof(){
if (empty($this->innerName)){
return true;
}else return $this->innerBof;
}
function recNo(){
return $this->curLine;
}
function recCount(){
return $this->innerCount;
}
function fieldsCount(){
if (empty($this->innerName)){
return false;
}else return $this->inner_F_Count;
}
function getValue($field){
if ($this->curLine==0||empty($this->innerName)){
echo "Can't read current record,maybe not in use or no record.";
return false;
}
$field= $this->chkField($field);
if ($field==-1){
return false;
}
return $this->curArray[$field];
}
function setValue($field,$value){
if ($this->curLine==0||empty($this->innerName)){
echo "Can't read current record,maybe not in use or no record.";
return false;
}
$field= $this->chkField($field);
if ($field==-1){
return false;
}
$this->curArray[$field]= $value;
$this->modify= true;
}
function display($shownon=0,$sprt1="
echo $sprt3;
foreach($this->curArray as $v){
if($shownon==1&&empty($v)) $v= "noValue";
echo $sprt1.$v.$sprt2;
}
echo $sprt4;
}
function location($field,$keyValue){
$field=$this->chkField($field);
if ($field==-1) return false;
for($i=$this->curLine;$iinnerCount;$i++){
if($this->curArray[$field]==$keyValue){
return true;
}
$this->next();
}
return false;
}
function del($recNo=-1){
if($this->curLine==0) return false;
$vartype= gettype($recNo);
if($vartype!="integer"){
echo "del error:check ur para type.";
return false;
}
if ($recNo==-1){
$recNo=$this->curLine;}
elseif ($recNo>$this->innerCount||$recNo echo "del error:out over the rang.";
return false;
}
if (!$this->chkDel($recNo)){
if(isset($this->stringDel)){
$this->stringDel.=(','.$recNo);
}else $this->stringDel = (string) $recNo;
}else return false;
}
function append($fields=""){
$this->saveModify();
for($i=1;$iinnerFieldsCount;$i++)
$newRec[] = "";
if(!empty($fields)){
foreach($fields as $k=>$v){
$k= $this->chkField($k);
if ($k==-1){
return false;
}
$newRec[$k]= $v;
}
}
$this->innerCount++;
$this->curLine = $this->innerCount;
$this->innerBof = false;
$this->innerEof = true;
unset($this->curArray);
$this->curArray = &$newRec;
$this->isModify = true;
}
//保存修改
function saveModify(){
if($this->isModify){
$this->innerRecorders[$this->curLine]= implode($this->sprt2,$this->curArray);
$this->isModify = false;
$this->fileModify= true;
}
}
//当指针发生变化时,初始化当前记录数组
function initRec(){
$this->curArray = explode($this->sprt2,$this->innerRecorders[$this->curLine]);
if (count($this->curArray)!=$this->innerFieldsCount){
echo "The Current Recorder fields count unequal to Table's.\n File will close.";
$this->close();
return false;
}
return true;
}
//输出当前记录信息,设计为调试用
function ddisplay(){
if ($this->innerCount==0) return false;
foreach($this->innerFields as $v) echo $v."----";
echo "
";
foreach($this->curArray as $v) echo $v."---";
}
//检查记录是否已被删除
function chkDel($key){
if (empty($key)&&$key!=0){
echo "the key not appoint.";
return false;
}
if (!isset($this->stringDel)){
return false;
}
if (ereg("(^|,)".$key."(,|$)",$this->stringDel)){
return true;
}
return false;
}
//检查提交的字段名是否合法.
function chkField($field){
if (empty($field)&&($field!=0)){
echo "the field not appoint.";
return -1;
}
$vartype = gettype($field);
switch ($vartype) {
case "integer":
if ($field>=$this->innerFieldsCount){
echo "the field is large than fieldscount";
return -1;
}elseif($field echo "the field is less than 0";
return -1;
}
return $field;
case "string":
foreach ($this->innerFields as $k=>$v) if ($field==$v) return $k;
echo "the field name not found.";
return -1;
default:
echo "the field is invalid.";
return -1;
}
}
}
?>

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

DDREASE是一种用于从文件或块设备(如硬盘、SSD、RAM磁盘、CD、DVD和USB存储设备)恢复数据的工具。它将数据从一个块设备复制到另一个块设备,留下损坏的数据块,只移动好的数据块。ddreasue是一种强大的恢复工具,完全自动化,因为它在恢复操作期间不需要任何干扰。此外,由于有了ddasue地图文件,它可以随时停止和恢复。DDREASE的其他主要功能如下:它不会覆盖恢复的数据,但会在迭代恢复的情况下填补空白。但是,如果指示工具显式执行此操作,则可以将其截断。将数据从多个文件或块恢复到单

0.这篇文章干了啥?提出了DepthFM:一个多功能且快速的最先进的生成式单目深度估计模型。除了传统的深度估计任务外,DepthFM还展示了在深度修复等下游任务中的最先进能力。DepthFM效率高,可以在少数推理步骤内合成深度图。下面一起来阅读一下这项工作~1.论文信息标题:DepthFM:FastMonocularDepthEstimationwithFlowMatching作者:MingGui,JohannesS.Fischer,UlrichPrestel,PingchuanMa,Dmytr

如果您需要了解如何在Excel中使用具有多个条件的筛选功能,以下教程将指导您完成相应步骤,确保您可以有效地对数据进行筛选和排序。Excel的筛选功能是非常强大的,能够帮助您从大量数据中提取所需的信息。这个功能可以根据您设定的条件,过滤数据并只显示符合条件的部分,让数据的管理变得更加高效。通过使用筛选功能,您可以快速找到目标数据,节省了查找和整理数据的时间。这个功能不仅可以应用在简单的数据列表上,还可以根据多个条件进行筛选,帮助您更精准地定位所需信息。总的来说,Excel的筛选功能是一个非常实用的

在C语言中,if语句通常用于基于单个条件执行特定代码块。但是,通过使用逻辑运算符(如 &&、|| 和 !),可以组合多个条件来进行判断。包括使用逻辑与(&&)判断多个条件、使用逻辑或(||)判断至少一个条件、使用逻辑非(!)判断单个条件的否定,以及嵌套if语句和使用括号明确优先级。

谷歌力推的JAX在最近的基准测试中性能已经超过Pytorch和TensorFlow,7项指标排名第一。而且测试并不是在JAX性能表现最好的TPU上完成的。虽然现在在开发者中,Pytorch依然比Tensorflow更受欢迎。但未来,也许有更多的大模型会基于JAX平台进行训练和运行。模型最近,Keras团队为三个后端(TensorFlow、JAX、PyTorch)与原生PyTorch实现以及搭配TensorFlow的Keras2进行了基准测试。首先,他们为生成式和非生成式人工智能任务选择了一组主流

哭死啊,全球狂炼大模型,一互联网的数据不够用,根本不够用。训练模型搞得跟《饥饿游戏》似的,全球AI研究者,都在苦恼怎么才能喂饱这群数据大胃王。尤其在多模态任务中,这一问题尤为突出。一筹莫展之际,来自人大系的初创团队,用自家的新模型,率先在国内把“模型生成数据自己喂自己”变成了现实。而且还是理解侧和生成侧双管齐下,两侧都能生成高质量、多模态的新数据,对模型本身进行数据反哺。模型是啥?中关村论坛上刚刚露面的多模态大模型Awaker1.0。团队是谁?智子引擎。由人大高瓴人工智能学院博士生高一钊创立,高

在iPhone上面临滞后,缓慢的移动数据连接?通常,手机上蜂窝互联网的强度取决于几个因素,例如区域、蜂窝网络类型、漫游类型等。您可以采取一些措施来获得更快、更可靠的蜂窝互联网连接。修复1–强制重启iPhone有时,强制重启设备只会重置许多内容,包括蜂窝网络连接。步骤1–只需按一次音量调高键并松开即可。接下来,按降低音量键并再次释放它。步骤2–该过程的下一部分是按住右侧的按钮。让iPhone完成重启。启用蜂窝数据并检查网络速度。再次检查修复2–更改数据模式虽然5G提供了更好的网络速度,但在信号较弱

最近,军事圈被这个消息刷屏了:美军的战斗机,已经能由AI完成全自动空战了。是的,就在最近,美军的AI战斗机首次公开,揭开了神秘面纱。这架战斗机的全名是可变稳定性飞行模拟器测试飞机(VISTA),由美空军部长亲自搭乘,模拟了一对一的空战。5月2日,美国空军部长FrankKendall在Edwards空军基地驾驶X-62AVISTA升空注意,在一小时的飞行中,所有飞行动作都由AI自主完成!Kendall表示——在过去的几十年中,我们一直在思考自主空对空作战的无限潜力,但它始终显得遥不可及。然而如今,
