发新话题
打印

PHP4手册:函数库及函数(八) DBA 函式库

本主题由 admin 于 2007-11-4 12:03 移动

PHP4手册:函数库及函数(八) DBA 函式库

--------------------------------------------------------------------------------
DBA 函式库  
--------------------------------------------------------------------------------
  

本函式库共有 12 个函式
在柏克莱的 BSD 系列作业系统中,有个简单的资料库结构,它以数个档案组成超小型的资料库系统,架构成抽象层 (abstraction layer) 的 DBA 资料库。
目前 PHP 支援的 DBA 资料库包括  
dbm:柏克莱发展的最早期 DBA 资料库。  
ndbm:较新且较有弹性的 DBA。  
gdbm:GNU 发展的 DBA,ftp://ftp.gnu.org/pub/gnu/gdbm/  
db2:由 Sleepycat 软体开发的 DB2 (非 IBM 的 DB2),http://www.sleepycat.com  
cdb:这是 qmail 作者开发快速可靠的 DBA,http://pobox.com/~djb/cdb.html  
以下是简单的使用范例,当然在使用前,必须先装好 DBA。
$id = dba_open("/tmp/test.db", "n", "db2");
if(!$id) {
    echo "dba_open failed\n";
    exit;
}
dba_replace("key", "This is an example!", $id);
if(dba_exists("key", $id)) {
    echo dba_fetch("key", $id);
    dba_delete("key", $id);
}
dba_close($id);
?>


dba_close: 关闭资料库。  
dba_delete: 删除指定资料。  
dba_exists: 检查键是否存在。  
dba_fetch: 取回指定资料。  
dba_firstkey: 取回首笔键值。  
dba_insert: 加入资料。  
dba_nextkey: 取回下笔键值。  
dba_popen: 开启并保持资料库连结。  
dba_open: 开启资料库连结。  
dba_optimize: 最佳化资料库。  
dba_replace: 更动或加入资料。  
dba_sync: 资料库同步化。  

--------------------------------------------------------------------------------
函式:dba_close()  
--------------------------------------------------------------------------------
  

DBA 函式库

dba_close
关闭资料库。
语法: void dba_close(int handle);
传回值: 无
函式种类: 资料库功能

  
  
内容说明  

本函式用来将已开启的资料库关闭。参数 handle 为开启资料库时所传回来的代号 ID。

  
  
参考  

dba_popen()  dba_open()   

--------------------------------------------------------------------------------
函式:dba_delete()  
--------------------------------------------------------------------------------
  

DBA 函式库

dba_delete
删除指定资料。
语法: int dba_delete(string key, int handle);
传回值: 整数
函式种类: 资料库功能

  
  
内容说明  

本函式将删除指定的资料。参数 key 为欲删除的键值 (key)。参数 handle 为开启资料库时所传回来的代号 ID。删除成功则传回 true 值。

  
  
参考  

dba_exists()  dba_fetch()  dba_insert()  dba_replace()   

--------------------------------------------------------------------------------
函式:dba_exists()  
--------------------------------------------------------------------------------
  

DBA 函式库

dba_exists
检查键是否存在。
语法: boolean dba_exists(string key, int handle);
传回值: 布林值
函式种类: 资料库功能

  
  
内容说明  

本函式用来检查指定的键是否存在。参数 key 为待检查的键值 (key)。参数 handle 为开启资料库时所传回来的代号 ID。若键存在则传回 true 值。

  
  
参考  

dba_delete()  dba_fetch()  dba_insert()  dba_replace()   

--------------------------------------------------------------------------------
函式:dba_fetch()  
--------------------------------------------------------------------------------
  

DBA 函式库

dba_fetch
取回指定资料。
语法: string dba_fetch(string key, int handle);
传回值: 字串
函式种类: 资料库功能

  
  
内容说明  

本函式取得指定的资料。参数 key 为欲取出资料的键值 (key)。参数 handle 为开启资料库时所传回来的代号 ID。传回值即为资料字串,若取出失败则传回 false。

  
  
参考  

dba_exists()  dba_delete()  dba_insert()  dba_replace()   

--------------------------------------------------------------------------------
函式:dba_firstkey()  
--------------------------------------------------------------------------------
  

DBA 函式库

dba_firstkey
取回首笔键值。
语法: string dba_firstkey(int handle);
传回值: 字串
函式种类: 资料库功能

  
  
内容说明  

本函式取得资料库的第一笔键值 (key)。参数 handle 为开启资料库时所传回来的代号 ID。传回值即为键值,若取出失败则传回 false。

  
  
参考  

dba_nextkey()   

--------------------------------------------------------------------------------
函式:dba_insert()  
--------------------------------------------------------------------------------
  

DBA 函式库

dba_insert
加入资料。
语法: boolean dba_insert(string key, string value, int handle);
传回值: 布林值
函式种类: 资料库功能

  
  
内容说明  

本函式将加入资料至资料库中。参数 key 为键值 (key) 字串。参数 value 为欲加入的资料内容。参数 handle 为开启资料库时所传回来的代号 ID。成功则传回 true 值。

  
  
参考  

dba_exists()  dba_fetch()  dba_delete()  dba_replace()   

--------------------------------------------------------------------------------
函式:dba_nextkey()  
--------------------------------------------------------------------------------
  

DBA 函式库

dba_nextkey
取回下笔键值。
语法: string dba_nextkey(int handle);
传回值: 字串
函式种类: 资料库功能

  
  
内容说明  

本函式取得资料库的下一笔键值 (key)。参数 handle 为开启资料库时所传回来的代号 ID。传回值即为键值,若取出失败则传回 false。

  
  
参考  

dba_firstkey()   

--------------------------------------------------------------------------------
函式:dba_popen()  
--------------------------------------------------------------------------------
  

DBA 函式库

dba_popen
开启并保持资料库连结。
语法: int dba_popen(string path, string mode, string handler);
传回值: 整数
函式种类: 资料库功能

  
  
内容说明  

本函式用来开启指定的资料库,并保持与资料库连线的状态。参数 path 为资料库的路径及资料库名称,例如 "/tmp/mysite/wahaha.db"。参数 mode 值如下表
属性 说明  
r 开启唯读既有资料库  
w 开启可读写既有资料库  
c 开启可读写资料库,若不存在则建立  
n 删去现有资料库,若不存在则建立,之后可读写  

参数 handler 为开启资料库的种类,有 dbm、ndbm、gdbm、db2 或 cdb 等种类。传回值为资料库的代号 ID,若失败则传回 false。

  
  
参考  

dba_close()  dba_open()   

--------------------------------------------------------------------------------
函式:dba_open()  
--------------------------------------------------------------------------------
  

DBA 函式库

dba_open
开启资料库连结。
语法: int dba_open(string path, string mode, string handler);
传回值: 整数
函式种类: 资料库功能

  
  
内容说明  

本函式用来开启指定的资料库。参数 path 为资料库的路径及资料库名称,例如 "/tmp/mysite/wahaha.db"。参数 mode 值如下表
属性 说明  
r 开启唯读既有资料库  
w 开启可读写既有资料库  
c 开启可读写资料库,若不存在则建立  
n 删去现有资料库,若不存在则建立,之后可读写  

参数 handler 为开启资料库的种类,有 dbm、ndbm、gdbm、db2 或 cdb 等种类。传回值为资料库的代号 ID,若失败则传回 false。本函式和 dba_popen() 不同的地方在于本函式开启的资料库在 PHP 程式结束后即关闭,dba_popen() 会保持与资料库连线,待下次再执行,则不必再打开与资料库的连结。

  
  
参考  

dba_close()  dba_popen()   

--------------------------------------------------------------------------------
函式:dba_optimize()  
--------------------------------------------------------------------------------
  

DBA 函式库

dba_optimize
最佳化资料库。
语法: boolean dba_optimize(int handle);
传回值: 布林值
函式种类: 资料库功能

  
  
内容说明  

本函式将资料库最佳化。参数 handle 为开启资料库时所传回来的代号 ID。最佳化成功则传回 true 值,反之则传回 false。

  
  
参考  

dba_sync()   
--------------------------------------------------------------------------------
函式:dba_replace()  
--------------------------------------------------------------------------------
  

DBA 函式库

dba_replace
更动或加入资料。
语法: boolean dba_replace(string key, string value, int handle);
传回值: 布林值
函式种类: 资料库功能

  
  
内容说明  

本函式更动资料库中的资料,若资料不存在则加入。参数 key 为键值 (key) 字串。参数 value 为欲更动的资料内容。参数 handle 为开启资料库时所传回来的代号 ID。成功则传回 true 值。

  
  
参考  

dba_exists()  dba_fetch()  dba_delete()  dba_insert()   

--------------------------------------------------------------------------------
函式:dba_sync()  
--------------------------------------------------------------------------------
  

DBA 函式库

dba_sync
资料库同步化。
语法: boolean dba_sync(int handle);
传回值: 布林值
函式种类: 资料库功能

  
  
内容说明  

本函式使系统在更新资料库时,能同时写入实体的资料库储存装置 (如硬碟) 之中。参数 handle 为开启资料库时所传回来的代号 ID。同步成功则传回 true 值,反之则传回 false。

  
  
参考  

dba_optimize()

TOP

发新话题