テキストデータベースブログの著者が書いたテキストデータベース操作クラスは非常に優れています。
数据|数据库
作者的1.0版:
/*
本代码开源,您可以对其进行修改.
下面文字请不要修改.
*********************************************
php文本数据库类1.0版
powerd by bpns
mysite:http://space.tju.cn/site/redboy/
2006-4-20
*********************************************
为了您的数据库安全,请在此程序中更改您的数据默认目录
将function TxtDB($name,$mod='w',$path='my_dbm')
中$path='my_dbm'修改成你自己设定的目录,如$path='abc123_dbm',
并将根目录下的my_dbm文件夹对行对应的更名.
*/
class TxtDB
{
var $name='';//文履歴库名
var $path='';
var $minLen=20;
var $isError;
var $dbh;
var $indxh;
var $lfth;
var $lckh;
var $rcdCnt=0;
var $maxID=0;
var $leftCnt=0;
var $DBend=0;
var $mod='w';
function TxtDB($name,$mod='w',$path='bpns_dbm')//修正データ架库の默认文件夹在此修正
{
$this->name=$name;
$this->path=$path.'/'.$name;
$this->isError=0;
$this->mod=$mod;
$path=$this->path;
if ($name!='')
{
@mkdir($this->path,0777);
if (!file_exists($path.'/'.$name.'.tdb')) $this->dbh=fopen($this->path.'/'.$name.'.tdb', 'w+');
else $this->dbh=fopen($path.'/'.$name.'.tdb','r+');
if (!file_exists($path.'/'.$name.'.indx')) $this->indxh=fopen($this->path.'/'.$name.'.indx', 'w+');
else $this->indxh=fopen($path.'/'.$name.'.indx','r+');
if (!file_exists($path.'/'.$name.'.lft')) $this->lfth=fopen($this->path.'/'.$name.'.lft', 'w+');
else $this->lfth=fopen($this->path.'/'.$name.'.lft','r+');
if ($this->mod=='w')
{
$this->lckh=fopen($this->path.'/'.$name.'.lck','w') ;
flock($this->lckh,2);
fwrite($this->lckh,'lck');// データベースをロックします
}
$rcd=$this->getRcd(0);
$this->rcdCnt=$rcd[id];
$this->maxID=$rcd[loc];
$this->DBend=$rcd[len];
$rcd=$this->getLeft(0);
$this->leftCnt=$rcd[loc];
}
else $this->isError=1;
}
function setRcd($rid,$id,$loc,$len)
{
fseek($this->indxh,$rid*12);
$str=pack('III',$id,$loc,$len);
fwrite($this->indxh,$str,12);
}
function getRcd($rid)
{
fseek($this->indxh,$rid*12);
$str=fread($this->indxh,12);
$rcd=array();
$rcd[id]=str2int($str);
$rcd[loc]=str2int(substr($str,4,4));
$rcd[len]=str2int(substr($str,8,4));
$rcd を返します。
}
function setLeft($lid,$loc,$len)
{
fseek($this->lfth,$lid*8);
$str=pack('II',$loc,$len);
fwrite($this->lfth,$str,8);
}
function getLeft($lid)
{
fseek($this->lfth,$lid*8);
$str=fread($this->lfth,8);
$rcd[loc]=str2int($str);
$rcd[len]=str2int(substr($str,4,4));
$rcd を返します。
}
function clear()
{
$this->setRcd(0,0,0,0);
$this->setLeft(0,0,0);
}
function close()
{
@fclose($this->dbh);
@fclose($this->indxh);
@fclose($this->lfth);
@fclose($this->lckh);
}
function lookSpace($len)
{
$res=array('loc'=>0,'len'=>0);
if ($this->leftCnt $find=0;
$min=1000000;
for ($i=$this->leftCnt;$i>0;$i--)
{
$res=$this->getLeft($i);
if ($res[len]==$len) {$find=$i;break;}
else if($res[len]>$len)
{
if ($res[len]-$len< ;$min)
{
$min=$res[len]-$len;
$find=$i;
}
}
}
if ($find)
{
$res=$this->getLeft($find);
if ($res[len] {
fseek($this->lfth,($find+1)*8);
$str=fread($this->lfth,($this->leftCnt-$find)*8);
fseek($this->lfth,$find*8);
fwrite($this->lfth,$str);
$this->leftCnt--;
$this->setLeft(0,$this->leftCnt,0);
$res を返します。
}
else
{
$rs=array();
$rs[loc]=$res[loc];
$rs[len]=$len;
$res[loc]+=$len;
$this->setLeft($find,$res[loc],$res[len]-$len);
$rs を返します。
}
}
else//fail
{
$res[len]=0;
$res を返します。
}
}
function insert($content,$len=0)//レコードIDを返します
{
$res=array('loc'=>0);
if ($this->mod!='w') は 0 を返します。
if (!$len) $len=strlen($content);
if ($len<$this->minLen) $len=$this->minLen;
if ($this->leftCnt) $res=$this->seekSpace($len);
if (!$res[len])
{
$res[loc]=$this->DBend;
$res[len]=$len;
}
if ($res[loc]+$res[len]>$this->DBend) $this->DBend=$res[loc]+$res[len];
//echo $this->DBend.'
';
$this->maxID++;
$this->rcdCnt++;
$this->setRcd(0,$this->rcdCnt,$this->maxID,$this->DBend);
$this->setRcd($this->rcdCnt,$this->maxID,$res[loc],$res[len]);
fseek($this->dbh,$res[loc]);
fwrite($this->dbh,$content,$len);
$this->maxID を返す;
}
function findByID($id)
{
if ($id<1 or $id>$this->maxID or $this->rcdCnt<1) return 0;
$left=1;
$right=$this->rcdCnt;
while($left<$right)
{
$mid=(int)(($left+$right)/2);
if ($mid==$left または $mid==$right) ブレーク;
$rcd=$this->getRcd($mid);
if ($rcd[id]==$id) $mid を返します。
else if($id<$rcd[id]) $right=$mid;
else $left=$mid;
}
//$rcd=$this->getRcd($mid);
//if ($rcd[id]==$id) $mid を返す;
$rcd=$this->getRcd($left);
if ($rcd[id]==$id) は $left を返します。
$rcd=$this->getRcd($right);
if ($rcd[id]==$id) は $right を返します。
0 を返します。
}
function delete($id)
{
if ($this->mod!='w') return 0;
$rid=$this->findByID($id);
if (!$rid) return;
$res=$this->getRcd($rid);
fseek($this->indxh,($rid+1)*12);
$str=fread($this->indxh,($this->rcdCnt-$i)*12);
fseek($this->indxh,$rid*12);
fwrite($this->indxh,$str);
$this->rcdCnt--;
if ($res[loc]+$res[len]==$this->DBend)
{
$this->DBend=$res[loc];
$this->setRcd(0,$this->rcdCnt,$this->maxID,$this->DBend);
}
else
{
$this->setRcd(0,$this->rcdCnt,$this->maxID,$this->DBend);
$this->leftCnt++;
$this->setLeft(0,$this->leftCnt,0);
$this->setLeft($this->leftCnt,$res[loc],$res[len]);
}
}
function update($id,$newcontent,$len=0)
{
if ($this->mod!='w') return;
$rid=$this->findByID($id);
if (!$rid) return;
if (!$len) $len=strlen($newcontent);
$rcd=$this->getRcd($rid);
if ($rcd[len]<$len)
{
$this->leftCnt++;
$this->setLeft(0,$this->leftCnt,0);
$this->setLeft($this->leftCnt,$rcd[loc],$rcd[len]);
$rcd[loc]=$this->DBend;
$rcd[len]=$len;
$this->DBend+=$len;
$this->setRcd(0,$this->rcdCnt,$this->maxID,$this->DBend);
$this->setRcd($rid,$rcd[id],$rcd[loc],$rcd[len]);
}
fseek($this->dbh,$rcd[loc]);
fwrite($this->dbh,$newcontent,$len);
//echo $id.'
'.$content.'
'.$len;
}
function selectByRid($rid)
{
$res=array('id'=>0,'content'=>'');
if ($rid<1 or $rid>$this->rcdCnt) return $res;
else $rcd=$this->getRcd($rid);
$res[id]=$rcd[id];
$res[len]=$rcd[len];
fseek($this->dbh,$rcd[loc]);
$res[content]=fread($this->dbh,$rcd[len]);
return $res;
}
function select($id)
{
return $this->selectByRid($this->findByID($id));
}
function backup()
{
copy($this->path.'/'.$this->name.'.tdb',$this->path.'/'.$this->name.'.tdb.bck');
copy($this->path.'/'.$this->name.'.indx',$this->path.'/'.$this->name.'.indx.bck');
copy($this->path.'/'.$this->name.'.lft',$this->path.'/'.$this->name.'.lft.bck');
}
function recover()
{
copy($this->path.'/'.$this->name.'.tdb.bck',$this->path.'/'.$this->name.'.tdb');
copy($this->path.'/'.$this->name.'.indx.bck',$this->path.'/'.$this->name.'.indx');
copy($this->path.'/'.$this->name.'.lft.bck',$this->path.'/'.$this->name.'.lft');
}
}
?>
作者的2.0版,生成dbm:
class TxtDB
{
var $name='';//文本数据库名
var $path='';
var $minLen=20;
var $isError;
var $dbh;
var $indxh;
var $lfth;
var $lckh;
var $rcdCnt=0;
var $maxID=0;
var $leftCnt=0;
var $DBend=0;
var $mod='w';
function TxtDB($name,$mod='w',$path='bpns_dbm')
{
$this->name=$name;
$this->path=$path.'/'.$name;
$this->isError=0;
$this->mod=$mod;
$path=$this->path;
if ($name!='')
{
@mkdir($this->path,0777);
if (!file_exists($path.'/'.$name.'.tdb')) $this->dbh=fopen($this->path.'/'.$name.'.tdb','w+');
else $this->dbh=fopen($path.'/'.$name.'.tdb','r+');
if (!file_exists($path.'/'.$name.'.indx')) $this->indxh=fopen($this->path.'/'.$name.'.indx','w+');
else $this->indxh=fopen($path.'/'.$name.'.indx','r+');
if (!file_exists($path.'/'.$name.'.lft')) $this->lfth=fopen($this->path.'/'.$name.'.lft','w+');
else $this->lfth=fopen($this->path.'/'.$name.'.lft','r+');
if ($this->mod=='w')
{
$this->lckh=fopen($this->path.'/'.$name.'.lck','w');
flock($this->lckh,2);
fwrite($this->lckh,'lck');//lock the datebase
}
$rcd=$this->getRcd(0);
$this->rcdCnt=$rcd[id];
$this->maxID=$rcd[loc];
$this->DBend=$rcd[len];
$rcd=$this->getLeft(0);
$this->leftCnt=$rcd[loc];
}
else $this->isError=1;
}
function setRcd($rid,$id,$loc,$len)
{
fseek($this->indxh,$rid*12);
$str=pack('III',$id,$loc,$len);
fwrite($this->indxh,$str,12);
}
function getRcd($rid)
{
fseek($this->indxh,$rid*12);
$str=fread($this->indxh,12);
$rcd=array();
$rcd[id]=str2int($str);
$rcd[loc]=str2int(substr($str,4,4));
$rcd[len]=str2int(substr($str,8,4));
return $rcd;
}
function setLeft($lid,$loc,$len)
{
fseek($this->lfth,$lid*8);
$str=pack('II',$loc,$len);
fwrite($this->lfth,$str,8);
}
function getLeft($lid)
{
fseek($this->lfth,$lid*8);
$str=fread($this->lfth,8);
$rcd[loc]=str2int($str);
$rcd[len]=str2int(substr($str,4,4));
return $rcd;
}
function clear()
{
$this->setRcd(0,0,0,0);
$this->setLeft(0,0,0);
}
function close()
{
@fclose($this->dbh);
@fclose($this->indxh);
@fclose($this->lfth);
@fclose($this->lckh);
}
function seekSpace($len)
{
$res=array('loc'=>0,'len'=>0);
if ($this->leftCnt<1) return $res;
$find=0;
$min=1000000;
for ($i=$this->leftCnt;$i>0;$i--)
{
$res=$this->getLeft($i);
if ($res[len]==$len) {$find=$i;break;}
else if($res[len]>$len)
{
if ($res[len]-$len<$min)
{
$min=$res[len]-$len;
$find=$i;
}
}
}
if ($find)
{
$res=$this->getLeft($find);
if ($res[len] {
fseek($this->lfth,($find+1)*8);
$str=fread($this->lfth,($this->leftCnt-$find)*8);
fseek($this->lfth,$find*8);
fwrite($this->lfth,$str);
$this->leftCnt--;
$this->setLeft(0,$this->leftCnt,0);
$res を返します。
}
else
{
$rs=array();
$rs[loc]=$res[loc];
$rs[len]=$len;
$res[loc]+=$len;
$this->setLeft($find,$res[loc],$res[len]-$len);
$rs を返します。
}
}
else//fail
{
$res[len]=0;
$res を返します。
}
}
function insert($content,$len=0)//レコードIDを返します
{
$res=array('loc'=>0);
if ($this->mod!='w') は 0 を返します。
if (!$len) $len=strlen($content);
if ($len<$this->minLen) $len=$this->minLen;
if ($this->leftCnt) $res=$this->seekSpace($len);
if (!$res[len])
{
$res[loc]=$this->DBend;
$res[len]=$len;
}
if ($res[loc]+$res[len]>$this->DBend) $this->DBend=$res[loc]+$res[len];
//echo $this->DBend.'
';
$this->maxID++;
$this->rcdCnt++;
$this->setRcd(0,$this->rcdCnt,$this->maxID,$this->DBend);
$this->setRcd($this->rcdCnt,$this->maxID,$res[loc],$res[len]);
fseek($this->dbh,$res[loc]);
fwrite($this->dbh,$content,$len);
$this->maxID を返す;
}
function findByID($id)
{
if ($id<1 or $id>$this->maxID or $this->rcdCnt<1) return 0;
$left=1;
$right=$this->rcdCnt;
while($left<$right)
{
$mid=(int)(($left+$right)/2);
if ($mid==$left または $mid==$right) ブレーク;
$rcd=$this->getRcd($mid);
if ($rcd[id]==$id) $mid を返します。
else if($id<$rcd[id]) $right=$mid;
else $left=$mid;
}
//$rcd=$this->getRcd($mid);
//if ($rcd[id]==$id) $mid を返す;
$rcd=$this->getRcd($left);
if ($rcd[id]==$id) は $left を返します。
$rcd=$this->getRcd($right);
if ($rcd[id]==$id) は $right を返します。
0 を返します。
}
function delete($id)
{
if ($this->mod!='w') return 0;
$rid=$this->findByID($id);
if (!$rid) return;
$res=$this->getRcd($rid);
fseek($this->indxh,($rid+1)*12);
$str=fread($this->indxh,($this->rcdCnt-$i)*12);
fseek($this->indxh,$rid*12);
fwrite($this->indxh,$str);
$this->rcdCnt--;
if ($res[loc]+$res[len]==$this->DBend)
{
$this->DBend=$res[loc];
$this->setRcd(0,$this->rcdCnt,$this->maxID,$this->DBend);
}
else
{
$this->setRcd(0,$this->rcdCnt,$this->maxID,$this->DBend);
$this->leftCnt++;
$this->setLeft(0,$this->leftCnt,0);
$this->setLeft($this->leftCnt,$res[loc],$res[len]);
}
}
function update($id,$newcontent,$len=0)
{
if ($this->mod!='w') return;
$rid=$this->findByID($id);
if (!$rid) return;
if (!$len) $len=strlen($newcontent);
$rcd=$this->getRcd($rid);
if ($rcd[len]<$len)
{
$this->leftCnt++;
$this->setLeft(0,$this->leftCnt,0);
$this->setLeft($this->leftCnt,$rcd[loc],$rcd[len]);
$rcd[loc]=$this->DBend;
$rcd[len]=$len;
$this->DBend+=$len;
$this->setRcd(0,$this->rcdCnt,$this->maxID,$this->DBend);
$this->setRcd($rid,$rcd[id],$rcd[loc],$rcd[len]);
}
fseek($this->dbh,$rcd[loc]);
fwrite($this->dbh,$newcontent,$len);
//echo $id.'
'.$content.'
'.$len;
}
function selectByRid($rid)
{
$res=array('id'=>0,'content'=>'');
if ($rid$this->rcdCnt) return $res;
else $rcd=$this->getRcd($rid);
$res[id]=$rcd[id];
$res[len]=$rcd[len];
fseek($this->dbh,$rcd[loc]);
$res[content]=fread($this->dbh,$rcd[len]);
//$res[rid]=$rid;
$res を返します。
}
function select($id)
{
return $this->selectByRid($this->gt;findByID($id));
}
function backup()
{
copy($this->path.'/'.$this->name.'.tdb',$this->path.'/'.$this-> ;名前.'.tdb.bck');
copy($this->path.'/'.$this->name.'.indx',$this->path.'/'.$this->name.'.indx.bck' );
copy($this->path.'/'.$this->name.'.lft',$this->path.'/'.$this->name.'.lft.bck' );
}
function reverse()
{
copy($this->path.'/'.$this->name.'.tdb.bck',$this->path.'/'.$this ->名前.'.tdb');
copy($this->path.'/'.$this->name.'.indx.bck',$this->path.'/'.$this->name.'.indx' );
copy($this->path.'/'.$this->name.'.lft.bck',$this->path.'/'.$this->name.'.lft' );
}
}
?>

ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

メモ帳++7.3.1
使いやすく無料のコードエディター

SublimeText3 中国語版
中国語版、とても使いやすい

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

ドリームウィーバー CS6
ビジュアル Web 開発ツール

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

ホットトピック











ログイン画面に「組織から PIN の変更を求められています」というメッセージが表示されます。これは、個人のデバイスを制御できる組織ベースのアカウント設定を使用しているコンピューターで PIN の有効期限の制限に達した場合に発生します。ただし、個人アカウントを使用して Windows をセットアップした場合、エラー メッセージは表示されないのが理想的です。常にそうとは限りませんが。エラーが発生したほとんどのユーザーは、個人アカウントを使用して報告します。私の組織が Windows 11 で PIN を変更するように要求するのはなぜですか?アカウントが組織に関連付けられている可能性があるため、主なアプローチはこれを確認することです。ドメイン管理者に問い合わせると解決できます。さらに、ローカル ポリシー設定が間違っていたり、レジストリ キーが間違っていたりすると、エラーが発生する可能性があります。今すぐ

Windows 11 では、新鮮でエレガントなデザインが前面に押し出されており、最新のインターフェイスにより、ウィンドウの境界線などの細部をカスタマイズして変更することができます。このガイドでは、Windows オペレーティング システムで自分のスタイルを反映した環境を作成するのに役立つ手順について説明します。ウィンドウの境界線の設定を変更するにはどうすればよいですか? + を押して設定アプリを開きます。 Windows [個人用設定] に移動し、[色の設定] をクリックします。ウィンドウの境界線の色の変更設定ウィンドウ 11" width="643" height="500" > [タイトル バーとウィンドウの境界線にアクセント カラーを表示する] オプションを見つけて、その横にあるスイッチを切り替えます。 [スタート] メニューとタスク バーにアクセント カラーを表示するにはスタート メニューとタスク バーにテーマの色を表示するには、[スタート メニューとタスク バーにテーマを表示] をオンにします。

デフォルトでは、Windows 11 のタイトル バーの色は、選択したダーク/ライト テーマによって異なります。ただし、任意の色に変更できます。このガイドでは、デスクトップ エクスペリエンスを変更し、視覚的に魅力的なものにするためにカスタマイズする 3 つの方法について、段階的な手順を説明します。アクティブなウィンドウと非アクティブなウィンドウのタイトル バーの色を変更することはできますか?はい、設定アプリを使用してアクティブなウィンドウのタイトル バーの色を変更したり、レジストリ エディターを使用して非アクティブなウィンドウのタイトル バーの色を変更したりできます。これらの手順を学習するには、次のセクションに進んでください。 Windows 11でタイトルバーの色を変更するにはどうすればよいですか? 1. 設定アプリを使用して + を押して設定ウィンドウを開きます。 Windows「個人用設定」に進み、

Windows インストーラー ページに「問題が発生しました」というメッセージとともに「OOBELANGUAGE」というメッセージが表示されますか?このようなエラーが原因で Windows のインストールが停止することがあります。 OOBE とは、すぐに使えるエクスペリエンスを意味します。エラー メッセージが示すように、これは OOBE 言語の選択に関連する問題です。心配する必要はありません。OOBE 画面自体から気の利いたレジストリ編集を行うことで、この問題を解決できます。クイックフィックス – 1. OOBE アプリの下部にある [再試行] ボタンをクリックします。これにより、問題が発生することなくプロセスが続行されます。 2. 電源ボタンを使用してシステムを強制的にシャットダウンします。システムの再起動後、OOBE が続行されます。 3. システムをインターネットから切断します。 OOBE のすべての側面をオフライン モードで完了する

タスクバーのサムネイルは楽しい場合もありますが、気が散ったり煩わしい場合もあります。この領域にマウスを移動する頻度を考えると、重要なウィンドウを誤って閉じてしまったことが何度かある可能性があります。もう 1 つの欠点は、より多くのシステム リソースを使用することです。そのため、リソース効率を高める方法を探している場合は、それを無効にする方法を説明します。ただし、ハードウェアの仕様が対応可能で、プレビューが気に入った場合は、有効にすることができます。 Windows 11でタスクバーのサムネイルプレビューを有効にする方法は? 1. 設定アプリを使用してキーをタップし、[設定] をクリックします。 Windows では、「システム」をクリックし、「バージョン情報」を選択します。 「システムの詳細設定」をクリックします。 [詳細設定] タブに移動し、[パフォーマンス] の下の [設定] を選択します。 「視覚効果」を選択します

多くのユーザーはスマートウォッチを選ぶときにファーウェイブランドを選択しますが、その中でもファーウェイ GT3pro と GT4 は非常に人気のある選択肢であり、多くのユーザーはファーウェイ GT3pro と GT4 の違いに興味を持っています。 Huawei GT3pro と GT4 の違いは何ですか? 1. 外観 GT4: 46mm と 41mm、材質はガラスミラー + ステンレススチールボディ + 高解像度ファイバーバックシェルです。 GT3pro: 46.6mm および 42.9mm、材質はサファイアガラス + チタンボディ/セラミックボディ + セラミックバックシェルです。 2. 健全な GT4: 最新の Huawei Truseen5.5+ アルゴリズムを使用すると、結果はより正確になります。 GT3pro: ECG 心電図と血管と安全性を追加

Windows 11 のディスプレイ スケーリングに関しては、好みが人それぞれ異なります。大きなアイコンを好む人もいれば、小さなアイコンを好む人もいます。ただし、適切なスケーリングが重要であることには誰もが同意します。フォントのスケーリングが不十分であったり、画像が過度にスケーリングされたりすると、作業中の生産性が大幅に低下する可能性があるため、システムの機能を最大限に活用するためにカスタマイズする方法を知る必要があります。カスタム ズームの利点: これは、画面上のテキストを読むのが難しい人にとって便利な機能です。一度に画面上でより多くの情報を確認できるようになります。特定のモニターおよびアプリケーションにのみ適用するカスタム拡張プロファイルを作成できます。ローエンド ハードウェアのパフォーマンスの向上に役立ちます。画面上の内容をより詳細に制御できるようになります。 Windows 11の使用方法

画面の明るさは、最新のコンピューティング デバイスを使用する上で不可欠な部分であり、特に長時間画面を見る場合には重要です。目の疲れを軽減し、可読性を向上させ、コンテンツを簡単かつ効率的に表示するのに役立ちます。ただし、設定によっては、特に新しい UI が変更された Windows 11 では、明るさの管理が難しい場合があります。明るさの調整に問題がある場合は、Windows 11 で明るさを管理するすべての方法を次に示します。 Windows 11で明るさを変更する方法【10の方法を解説】 シングルモニターユーザーは、次の方法でWindows 11の明るさを調整できます。これには、ラップトップだけでなく、単一のモニターを使用するデスクトップ システムも含まれます。はじめましょう。方法 1: アクション センターを使用する アクション センターにアクセスできる
