投稿说明 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 ...
[详细]
-
本文探讨了如何通过最小生成树(MST)来计算严格次小生成树。在处理过程中,需特别注意所有边权重相等的情况,以避免错误。我们首先构建最小生成树,然后枚举每条非树边,检查其是否能形成更优的次小生成树。 ...
[详细]
-
QUIC(Quick UDP Internet Connections)是谷歌开发的一种旨在提高网络性能和安全性的传输层协议。它基于UDP,并结合了TLS级别的安全性,提供了更高效、更可靠的互联网通信方式。 ...
[详细]
-
本文介绍了OAuth认证协议的核心概念及其工作原理。OAuth是一种开放标准,旨在为第三方应用提供安全的用户资源访问授权,同时确保用户的账户信息(如用户名和密码)不会暴露给第三方。 ...
[详细]
-
2023 ARM嵌入式系统全国技术巡讲旨在分享ARM公司在半导体知识产权(IP)领域的最新进展。作为全球领先的IP提供商,ARM在嵌入式处理器市场占据主导地位,其产品广泛应用于90%以上的嵌入式设备中。此次巡讲将邀请来自ARM、飞思卡尔以及华清远见教育集团的行业专家,共同探讨当前嵌入式系统的前沿技术和应用。 ...
[详细]
-
本文介绍如何使用 Oracle 存储函数查询特定员工的年收入。我们将详细解释存储函数的创建过程,并提供完整的代码示例。 ...
[详细]
-
本文总结了2018年的关键成就,包括职业变动、购车、考取驾照等重要事件,并分享了读书、工作、家庭和朋友方面的感悟。同时,展望2019年,制定了健康、软实力提升和技术学习的具体目标。 ...
[详细]
-
在计算机技术的学习道路上,51CTO学院以其专业性和专注度给我留下了深刻印象。从2012年接触计算机到2014年开始系统学习网络技术和安全领域,51CTO学院始终是我信赖的学习平台。 ...
[详细]
-
本文介绍了如何使用 CSS 实现液态的三栏布局,其中各栏具有不同的宽度设置。通过调整容器和内容区域的属性,可以实现灵活且响应式的网页设计。 ...
[详细]
-
本文详细介绍了 Linux 系统启动过程中常见的 MBR 扇区和 GRUB 引导程序故障及其解决方案,涵盖从备份、模拟故障到恢复的具体步骤。 ...
[详细]
-
本文介绍了如何使用jQuery根据元素的类型(如复选框)和标签名(如段落)来获取DOM对象。这有助于更高效地操作网页中的特定元素。 ...
[详细]
-
本文详细介绍了 PHP 5.2.5 的安装和配置步骤,帮助开发者解决常见的环境配置问题,特别是上传图片时遇到的错误。通过本教程,您可以顺利搭建并优化 PHP 运行环境。 ...
[详细]
-
本文详细介绍了如何通过HTTP响应和请求处理浏览器的Cookie信息,以及如何创建、设置和管理Cookie。同时探讨了会话跟踪技术中的Session机制,解释其原理及应用场景。 ...
[详细]
-
Tags | 热门标签
RankList | 热门文章
-
1一招判断云主机IP是不是原生IP
-
2input内容右对齐_STM32学习笔记—DAC基础内容及常见问题
-
3Elastic Search 7.0 添加数据提示 提示503错误
-
4有关phpfgetss()函数的文章推荐10篇
-
5SmartMining
-
6java读取excel中的数据
-
7[急!] c#如何直接操作ppt的图表数据,winfrom下mschart图表如何倒入到excel或ppt中
-
8i5 10400f配什么主板性价比高
-
9R语言openxlsx、car、rmarkdown包安装报错: 句法分析器2行里不能有多字节字符;解决WARNING: Rtools is required to build R packages
-
10西安小程序开发,小程序制作,一个后台管理多端小程序功能性
-
11优先级表和Ascll表
-
12XMLhttpREquest_Ajax技术总结之XmlHttpRequest
-
13获取php数组的最后5个元素,php获取数组最后一个元素
-
14作用域链&&严厉形式
-
15Form表单里的checkbox能用required判断至少选择一个吗
标签: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 ... [详细]本文探讨了如何通过最小生成树(MST)来计算严格次小生成树。在处理过程中,需特别注意所有边权重相等的情况,以避免错误。我们首先构建最小生成树,然后枚举每条非树边,检查其是否能形成更优的次小生成树。 ... [详细]QUIC(Quick UDP Internet Connections)是谷歌开发的一种旨在提高网络性能和安全性的传输层协议。它基于UDP,并结合了TLS级别的安全性,提供了更高效、更可靠的互联网通信方式。 ... [详细]本文介绍了OAuth认证协议的核心概念及其工作原理。OAuth是一种开放标准,旨在为第三方应用提供安全的用户资源访问授权,同时确保用户的账户信息(如用户名和密码)不会暴露给第三方。 ... [详细]2023 ARM嵌入式系统全国技术巡讲旨在分享ARM公司在半导体知识产权(IP)领域的最新进展。作为全球领先的IP提供商,ARM在嵌入式处理器市场占据主导地位,其产品广泛应用于90%以上的嵌入式设备中。此次巡讲将邀请来自ARM、飞思卡尔以及华清远见教育集团的行业专家,共同探讨当前嵌入式系统的前沿技术和应用。 ... [详细]本文介绍如何使用 Oracle 存储函数查询特定员工的年收入。我们将详细解释存储函数的创建过程,并提供完整的代码示例。 ... [详细]本文总结了2018年的关键成就,包括职业变动、购车、考取驾照等重要事件,并分享了读书、工作、家庭和朋友方面的感悟。同时,展望2019年,制定了健康、软实力提升和技术学习的具体目标。 ... [详细]在计算机技术的学习道路上,51CTO学院以其专业性和专注度给我留下了深刻印象。从2012年接触计算机到2014年开始系统学习网络技术和安全领域,51CTO学院始终是我信赖的学习平台。 ... [详细]本文介绍了如何使用 CSS 实现液态的三栏布局,其中各栏具有不同的宽度设置。通过调整容器和内容区域的属性,可以实现灵活且响应式的网页设计。 ... [详细]本文详细介绍了 Linux 系统启动过程中常见的 MBR 扇区和 GRUB 引导程序故障及其解决方案,涵盖从备份、模拟故障到恢复的具体步骤。 ... [详细]本文介绍了如何使用jQuery根据元素的类型(如复选框)和标签名(如段落)来获取DOM对象。这有助于更高效地操作网页中的特定元素。 ... [详细]本文详细介绍了 PHP 5.2.5 的安装和配置步骤,帮助开发者解决常见的环境配置问题,特别是上传图片时遇到的错误。通过本教程,您可以顺利搭建并优化 PHP 运行环境。 ... [详细]本文详细介绍了如何通过HTTP响应和请求处理浏览器的Cookie信息,以及如何创建、设置和管理Cookie。同时探讨了会话跟踪技术中的Session机制,解释其原理及应用场景。 ... [详细]Tags | 热门标签RankList | 热门文章
- 1一招判断云主机IP是不是原生IP
- 2input内容右对齐_STM32学习笔记—DAC基础内容及常见问题
- 3Elastic Search 7.0 添加数据提示 提示503错误
- 4有关phpfgetss()函数的文章推荐10篇
- 5SmartMining
- 6java读取excel中的数据
- 7[急!] c#如何直接操作ppt的图表数据,winfrom下mschart图表如何倒入到excel或ppt中
- 8i5 10400f配什么主板性价比高
- 9R语言openxlsx、car、rmarkdown包安装报错: 句法分析器2行里不能有多字节字符;解决WARNING: Rtools is required to build R packages
- 10西安小程序开发,小程序制作,一个后台管理多端小程序功能性
- 11优先级表和Ascll表
- 12XMLhttpREquest_Ajax技术总结之XmlHttpRequest
- 13获取php数组的最后5个元素,php获取数组最后一个元素
- 14作用域链&&严厉形式
- 15Form表单里的checkbox能用required判断至少选择一个吗