投稿说明 bitsCN.com > 编程/数据库 > PHP >
国外好东西真的多,现在贴上一个访问ACCESS的类!
标签:Access
这是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","cdi@thewebmasters.net))
{
echo "Error adding entry: $dbase->ERROR\n";
}
$Values = $dbase->get_all()
while ( list ($key,$val) = each ($Values) )
{
echo "Key: $key Val: $val \n";
}
exit;
推荐阅读
-
1:有如下一段程序:packagea.b.c;publicclassTest{privatestaticinti0;publicintgetNext(){return ...
[详细]
-
QUIC(Quick UDP Internet Connections)是谷歌开发的一种旨在提高网络性能和安全性的传输层协议。它基于UDP,并结合了TLS级别的安全性,提供了更高效、更可靠的互联网通信方式。 ...
[详细]
-
本文介绍了OAuth认证协议的核心概念及其工作原理。OAuth是一种开放标准,旨在为第三方应用提供安全的用户资源访问授权,同时确保用户的账户信息(如用户名和密码)不会暴露给第三方。 ...
[详细]
-
2023 ARM嵌入式系统全国技术巡讲旨在分享ARM公司在半导体知识产权(IP)领域的最新进展。作为全球领先的IP提供商,ARM在嵌入式处理器市场占据主导地位,其产品广泛应用于90%以上的嵌入式设备中。此次巡讲将邀请来自ARM、飞思卡尔以及华清远见教育集团的行业专家,共同探讨当前嵌入式系统的前沿技术和应用。 ...
[详细]
-
尽管商业智能(BI)工具在中国的普及程度尚不及国际市场,但近年来,随着本土企业的持续创新和市场推广,国内主流BI工具正逐渐崭露头角。面对国际品牌如Tableau的强大竞争,国内BI工具通过不断优化产品和技术,赢得了越来越多用户的认可。 ...
[详细]
-
本文介绍如何使用 Oracle 存储函数查询特定员工的年收入。我们将详细解释存储函数的创建过程,并提供完整的代码示例。 ...
[详细]
-
本文总结了2018年的关键成就,包括职业变动、购车、考取驾照等重要事件,并分享了读书、工作、家庭和朋友方面的感悟。同时,展望2019年,制定了健康、软实力提升和技术学习的具体目标。 ...
[详细]
-
本文详细介绍了 Linux 系统启动过程中常见的 MBR 扇区和 GRUB 引导程序故障及其解决方案,涵盖从备份、模拟故障到恢复的具体步骤。 ...
[详细]
-
本文介绍了如何使用jQuery根据元素的类型(如复选框)和标签名(如段落)来获取DOM对象。这有助于更高效地操作网页中的特定元素。 ...
[详细]
-
本文详细介绍了 PHP 5.2.5 的安装和配置步骤,帮助开发者解决常见的环境配置问题,特别是上传图片时遇到的错误。通过本教程,您可以顺利搭建并优化 PHP 运行环境。 ...
[详细]
-
本文详细介绍了如何通过HTTP响应和请求处理浏览器的Cookie信息,以及如何创建、设置和管理Cookie。同时探讨了会话跟踪技术中的Session机制,解释其原理及应用场景。 ...
[详细]
-
本文介绍如何在 Xcode 中使用快捷键和菜单命令对多行代码进行缩进,包括右缩进和左缩进的具体操作方法。 ...
[详细]
-
本文介绍了一款用于自动化部署 Linux 服务的 Bash 脚本。该脚本不仅涵盖了基本的文件复制和目录创建,还处理了系统服务的配置和启动,确保在多种 Linux 发行版上都能顺利运行。 ...
[详细]
-
Tags | 热门标签
标签:Access
这是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","cdi@thewebmasters.net))
{
echo "Error adding entry: $dbase->ERROR\n";
}
$Values = $dbase->get_all()
while ( list ($key,$val) = each ($Values) )
{
echo "Key: $key Val: $val \n";
}
exit;
推荐阅读
-
1:有如下一段程序:packagea.b.c;publicclassTest{privatestaticinti0;publicintgetNext(){return ... [详细]QUIC(Quick UDP Internet Connections)是谷歌开发的一种旨在提高网络性能和安全性的传输层协议。它基于UDP,并结合了TLS级别的安全性,提供了更高效、更可靠的互联网通信方式。 ... [详细]本文介绍了OAuth认证协议的核心概念及其工作原理。OAuth是一种开放标准,旨在为第三方应用提供安全的用户资源访问授权,同时确保用户的账户信息(如用户名和密码)不会暴露给第三方。 ... [详细]2023 ARM嵌入式系统全国技术巡讲旨在分享ARM公司在半导体知识产权(IP)领域的最新进展。作为全球领先的IP提供商,ARM在嵌入式处理器市场占据主导地位,其产品广泛应用于90%以上的嵌入式设备中。此次巡讲将邀请来自ARM、飞思卡尔以及华清远见教育集团的行业专家,共同探讨当前嵌入式系统的前沿技术和应用。 ... [详细]尽管商业智能(BI)工具在中国的普及程度尚不及国际市场,但近年来,随着本土企业的持续创新和市场推广,国内主流BI工具正逐渐崭露头角。面对国际品牌如Tableau的强大竞争,国内BI工具通过不断优化产品和技术,赢得了越来越多用户的认可。 ... [详细]本文介绍如何使用 Oracle 存储函数查询特定员工的年收入。我们将详细解释存储函数的创建过程,并提供完整的代码示例。 ... [详细]本文总结了2018年的关键成就,包括职业变动、购车、考取驾照等重要事件,并分享了读书、工作、家庭和朋友方面的感悟。同时,展望2019年,制定了健康、软实力提升和技术学习的具体目标。 ... [详细]本文详细介绍了 Linux 系统启动过程中常见的 MBR 扇区和 GRUB 引导程序故障及其解决方案,涵盖从备份、模拟故障到恢复的具体步骤。 ... [详细]本文介绍了如何使用jQuery根据元素的类型(如复选框)和标签名(如段落)来获取DOM对象。这有助于更高效地操作网页中的特定元素。 ... [详细]本文详细介绍了 PHP 5.2.5 的安装和配置步骤,帮助开发者解决常见的环境配置问题,特别是上传图片时遇到的错误。通过本教程,您可以顺利搭建并优化 PHP 运行环境。 ... [详细]本文详细介绍了如何通过HTTP响应和请求处理浏览器的Cookie信息,以及如何创建、设置和管理Cookie。同时探讨了会话跟踪技术中的Session机制,解释其原理及应用场景。 ... [详细]本文介绍如何在 Xcode 中使用快捷键和菜单命令对多行代码进行缩进,包括右缩进和左缩进的具体操作方法。 ... [详细]本文介绍了一款用于自动化部署 Linux 服务的 Bash 脚本。该脚本不仅涵盖了基本的文件复制和目录创建,还处理了系统服务的配置和启动,确保在多种 Linux 发行版上都能顺利运行。 ... [详细]Tags | 热门标签