首页 | 资讯动态 | linux基础 | 系统管理 | 网络管理 | 编程开发 | linux数据库 | 服务器技术 | linux相关 | linux认证 | 嵌入式 | 下载中心 | 专题 | linux招聘 | 镜像站
OKLinux中文技术站
·设为首页
·加入收藏
·联系我们
系统管理: 中文环境 系统管理 桌面应用 内核技术 | Linux基础: 基础入门 安装配置 常用命令 经验技巧 软件应用 | Linux数据库: Mysql Postgre Oracle DB2 Sybase other
网络管理: 网络安全 网络应用 Linux服务器 环境配置 黑客安全 | 编程开发: PHP CC++ Python Perl Shell 嵌入式开发 java jsp | PHP技术: PHP基础 PHP技巧 PHP应用 PHP文摘
Linux资讯 Linux招聘 Linux专题 Apache | Linux相关: 硬件相关 Linux解决方案 Linux认证 企业应用 其它Unix | 相关下载: 资料下载 参考手册 开发工具 服务器类 软路由 其它
 技术搜索:
会员中心 注册会员 高级搜索  
  → 当前位置:首页>编程开发>php>php技巧>正文

一个访问ACCESS的类

http://www.oklinux.cn  2003-05-01  来源: 互联网    会员收藏  游客收藏  【 】 

这是ACCESS的类

<?
Class AccessDBM
{
var $COUNT = 0;
var $VALUES = array();
var $FILE = "";
var $ERROR = "";
var $EXISTS = false;
var $STATIC = false;
var $EXACT = false;
var $DBM;

//    Older version of PHP can't do the 'new ClassName(args)'
//    Use initilize() if this is the case.

//    *******************************************************

function AccessDBM ($dbmFile, $static = 0)
{
global $php_errormsg;

if(!empty($dbmFile))
{
if(file_exists($dbmFile))
{
$this->EXISTS = true;
}
if($static != 0)
{
$this->STATIC = true;
}
$this->FILE = $dbmFile;
}
return;
}

//    *******************************************************

//    Identical to AccessDBM
function initialize ($dbmFile, $static = 0)
{
global $php_errormsg;

if(!empty($dbmFile))
{
if(file_exists($dbmFile))
{
$this->EXISTS = true;
}
if($static != 0)
{
$this->STATIC = true;
}
$this->FILE = $dbmFile;
}
return;
}

//    *******************************************************

function add_entry ($key, $val)
{
$results = 0;
$dbm = $this->open_dbm();
if(!$dbm) { return false; }

if(!(dbmreplace($dbm,$key,$val)))
{
if(!(dbmexists($dbm,$key)))
{
$this->ERROR = "Fatal error : could not replace $key with $val";
$this->close_dbm($dbm);
return false;
}
}
$this->close_dbm($dbm);
return true;        
}

//    *******************************************************

function remove_entry ($Key)
{
global $php_errormsg;
$removed = false;

$dbm = $this->open_dbm();
if(!$dbm) { return false; }

if(dbmexists($dbm,$Key))
{
if(!dbmdelete($dbm,$Key))
{
if(dbmexists($dbm,$Key))
{
$this->ERROR = "Unable to remove [$Key] : [$php_errormsg]";
$this->close_dbm($dbm);
return false;
}
}
else
{
$this->close_dbm($dbm);
$removed = true;
}
}
else
{
$this->ERROR = "Key [$Key] does not exist";
$this->close_dbm($dbm);
return false;
}
return true;
}

//    *******************************************************

function get_value ($Key)
{
$val = "";
$readOnly = true;

$dbm = $this->open_dbm($readOnly);

if(!$dbm) { return false; }

if(dbmexists($dbm,$Key))
{
$val = dbmfetch($dbm,$Key);
}
$this->close_dbm($dbm);
return $val;
}

//    *******************************************************

function open_dbm ($readOnly = false)
{
global $php_errormsg;

if($this->STATIC)
{
if(!(empty($this->DBM)))
{
$dbm = $this->DBM;
return ($dbm);
}
}

$fileName = $this->FILE;

if(!$this->EXISTS)
{
$dbm = @dbmopen($fileName,"n");
}
else
{
if(!$readOnly)
{
// We want the warning here if we can't be
// a writer
$dbm = dbmopen($fileName,"w");
}
else
{
$dbm = @dbmopen($fileName,"r");
}
}
if( (!$dbm) or (empty($dbm)) )
{
$this->EXISTS = false;
$this->STATIC = false;
$this->ERROR = "Unable to open [$fileName] [$php_errormsg]";
return false;
}
$this->EXISTS = true;
if($this->STATIC)
{
$this->DBM = $dbm;
}

return ($dbm);

}

//    *******************************************************

function find_key ($search)
{
$val = "";

$dbm = $this->open_dbm(1);
if(!$dbm) { return false; }
if(dbmexists($dbm,$search))
{
// Wow an exact match
$val = dbmfetch($dbm,$search);
$this->close_dbm($dbm);
$this->EXACT = true;
return $val;
}
else
{
$this->EXACT = false;
$key = dbmfirstkey($dbm);
while ($key)
{
// Strip the first whitespace char and
// everything after it.
$test = ereg_replace(" .*","",$key);
if(eregi("^$test",$search))
{
$val = dbmfetch($dbm,$key);
$this->close_dbm($dbm);
error_log("Test [$test] matched [$search]",0);
return $val;
}
$key = dbmnextkey($dbm,$key);
}
}
// Didn't find it
$this->close_dbm($dbm);
return false;
}

//    *******************************************************

// Returns the KEY
function find_val ($search)
{
$this->EXACT = false;

$Dbase = $this->get_all();
if(empty($Dbase))
{
error_log("ERROR Dbase is empty $DB->ERROR",0);
return false;
}
while ( list ( $key, $val ) = each ($Dbase) )
{
if($search == $val)
{
$this->EXACT=true;
return $key;
}
else
{
// Strip the first whitespace char and
// everything after it.

$test = ereg_replace(" .*","",$val);

if(eregi("^$test",$search))
{
$this->EXACT = false;
return $key;
}
}
}
// Didn't find it
return false;
}

//    *******************************************************

function get_all ()
{
$values = array();
$count = 0;
$readOnly = true;
$dbm = $this->open_dbm($readOnly);
if(!$dbm) { return false; }

$key = dbmfirstkey($dbm);

while ($key)
{
$val = dbmfetch($dbm,$key);
$values[$key] = $val;
$count++;
$key = dbmnextkey($dbm, $key);
}
$this->COUNT = $count;
$this->VALUES = $values;
$this->close_dbm($dbm);
return $values;
}

//    *******************************************************

function close_dbm ($dbm)
{
$results = false;

if(!$this->STATIC)
{
$results = dbmclose($dbm);
}
return $results;
}

//    *******************************************************

function static_close()
{
$results = false;

if(!$this->DBM)
{
$this->ERROR = "No static DBM to close";
return false;
}
$dbm = $this->DBM;
$results = dbmclose($dbm);
unset($this->DBM);
return $results;
}

//    *******************************************************

}
?>

这个连接上!
include("class.AccessDBM.php3");
$static = true;
$dbase = new AccessDBM("/path/to/file.dbm",$static);

register_shutdown_function($dbase->static_close());

if(!$dbase->add_entry("cdi","[email protected]))
{
echo "Error adding entry: $dbase->ERRORn";
}
$Values = $dbase->get_all()
while ( list ($key,$val) = each ($Values) )
{
echo "Key: $key  Val: $val n";
}
exit;


非常全面的一个php技术网站,

上一篇:一个分页导航类   下一篇:一个翻页类


收藏于收藏夹】 【评论】 【推荐】 【打印】 【关闭
相关文档
·一个分页导航类
·一个翻页类
·一个分页导航类示例
·一个操作xml的类
·一个饼状图或柱状图php生成类或例子
·一个改进的UBB类
·一个好用的UBB类
·一个比较完善的购物车类
·一个PHP类
·一个简单编程思想在php与java中的实现比较:日期类
·新作模板处理类
·一个简单的IMAP类和应用
·无限分类&树型论坛的实现
·一个解析mp3 ID3 tag和MPEG信息的类
·贴个购物车的类,只用了一个Session
·一个无限分类的处理类
发表评论
密码: 匿名评论
评论内容:

(不超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规)
 
  最新文档
·PHP之COOKIE支持详解
·PHP中的类
·php中文处理函数
·通过ODBC连接的SQL
·两个日期类
·面向对象编程
·面向过程与面向对象的简单比较
·判断WebSERVER类型
·屏蔽浏览器缓存另类方法
·日历类
·如何文档化你的PHP类
·使用PHP4中的 IntegratedTemplate类实
  阅读排行
·PHP之COOKIE支持详解
·PHP 应用程序配置模式
·用 PHP 读取文件的正确方法
·利用单元测试对PHP 代码进行检查
·五个常见 PHP 数据库问题
·用 PHP V4 开发的代码迁移到 PHP V5
·使用PHP 快速生成Flash 动画
·Linux系统下PHP服务器安全配置技巧
·Linux操作系统下的多线程编程详细解析
·用PHP读取和编写XML DOM
·用Pear加速PHP程序开发
·如何用PHP调用自己编写的COM组件?
·PHP面向对象编程快速入门
·为 Linux 和 Windows 安装 PHP 和 Orac
·终于实现简体转繁体,繁体到转体
网摘收藏: