百科狗-知识改变命运!
--

dba_open() - dba函数(数据库抽象层)

是丫丫呀12个月前 (11-21)阅读数 7#技术干货
文章标签返回值

dba_open()

(PHP 4, PHP 5, PHP 7)

Open database

说明

dba_open(string $path,string $mode[,string $handler[,string$...]]): resource

dba_open() establishes a database instance for$pathwith$modeusing$handler.

参数

$path

Commonly a regular path in your filesystem.

$mode

It isrfor read access,wfor read/write access to an already existing database,cfor read/write access and database creation if it doesn't currently exist, andnfor create, truncate and read/write access. The database is created in BTree mode, other modes(like Hash or Queue)are not supported.

Additionally you can set the database lock method with the next char. Uselto lock the database with a.lckfile ordto lock the databasefile itself. It is important that all of your applications do this consistently.

If you want to test the access and do not want to wait for the lock you can addtas third character. When you are absolutely sure that you do not require database locking you can do so by using-instead oflord. When none ofd,lor-is used, dba will lock on the database file as it would withd.

Note:

There can only be one writer for one database file. When you use dba on a web server and more than one request requires write operations they can only be done one after another. Also read during write is not allowed. The dba extension uses locks to prevent this. See the following table:DBA lockingalready open$mode= "rl"$mode= "rlt"$mode= "wl"$mode= "wlt"$mode= "rd"$mode= "rdt"$mode= "wd"$mode= "wdt"not openokokokokokokokok$mode= "rl"okokwaitfalseillegalillegalillegalillegal$mode= "wl"waitfalsewaitfalseillegalillegalillegalillegal$mode= "rd"illegalillegalillegalillegalokokwaitfalse$mode= "wd"illegalillegalillegalillegalwaitfalsewaitfalse

  • ok: the second call will be successfull.
  • wait: the second call waits until dba_close() is called for the first.
  • false: the second call returns false.
  • illegal: you must not mix"l"and"d"modifiers for$modeparameter.
$handler

The name of the handler which shall be used for accessing$path. It is passed all optional parameters given to dba_open() and can act on behalf of them.

...

dba_open() - dba函数(数据库抽象层)

Optional string parameters which are passed to the driver.

Thecdb,cdb_make,flatfile,inifile,qdbmandtcadbdrivers do not support additional parameters.

Thedb1,db2,db3,db4,dbm,gdbm,lmdb, andndbmdrivers supports a single additional parameter$filemode, which has the same meaning as the$modeparameter of chmod(), and defaults to0644.

返回值

Returns a positive handle on success 或者在失败时返回FALSE.

参见

  • dba_popen()Open database persistently
  • dba_close()Close a DBA database
Windows does not support locking the database. You may use $_ENV to determine the OS:
$locking = (stripos($_ENV['OS'],'windows') === false ? 'd' : 'l');
As of GDBM version 1.8.3, GDBM's underlying open call uses non-blocking calls to flock() on systems that have flock(). As a result, calls with "rd" or "wd" locking modes will return error ("Can't be reader" or "Can't be writer") instead of waiting. Use "rl" or "wl" instead, to make PHP do its own locking external to GDBM.
Here's a simple example to use the dba_open function 
If you get some strange errors like
dba_open(): myDbFilename.db : Permission denied
than you are propably using PHP on a Windoze machine. You have to make sure that the following conditions are met:
1) Use an absolute path to your db file. Relative paths will cause problems with locking
2) Specify a locking mode - that's the second character of the mode-argument, or else opening a dba-file will cause several notices/warnings etc.
And a final, general note:
3) Always use the english PHP doc on this site - the translations are often old as hell and miss important informations
HTH, Nils.
Apache doesn't support Berkeley DB Btree, so you can't manipulate use db4 as the type of database if you want to do DBM authentication with Apache.
gdbm seemed to work fine though, even though it supposedly using Btree instead of hash. It makes you wonder why Apache would use hash for one dbmtype versus btree for another.
So since Apache and PHP don't have options to choose the method for the Berkeley DBs, you are out of luck.
Note the “c” create flag does not work if MySQL was built with the “cdb” DBA handler compile option which is common for many distros. By definition the cdb DBA handler is optimized for reading/writing and “no updates are allowed.” 

鹏仔微信 15129739599 鹏仔QQ344225443 鹏仔前端 pjxi.com 共享博客 sharedbk.com

免责声明:我们致力于保护作者版权,注重分享,当前被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理!邮箱:344225443@qq.com)

图片声明:本站部分配图来自网络。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!

内容声明:本文中引用的各种信息及资料(包括但不限于文字、数据、图表及超链接等)均来源于该信息及资料的相关主体(包括但不限于公司、媒体、协会等机构)的官方网站或公开发表的信息。部分内容参考包括:(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供参考使用,不准确地方联系删除处理!本站为非盈利性质站点,本着为中国教育事业出一份力,发布内容不收取任何费用也不接任何广告!)