(PHP 4, PHP 5, PHP 7)
dba_open — Open database
$...]] ) : resource
dba_open() establishes a database instance for
Commonly a regular path in your filesystem.
It is r for read access, w for read/write access to an already existing database, c for read/write access and database creation if it doesn't currently exist, and n for 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. Use l to lock the database with a .lck file or d to 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 add t as third character. When you are absolutely sure that you do not require database locking you can do so by using - instead of l or d. When none of d, l or - is used, dba will lock on the database file as it would with d.
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 locking already open
not open ok ok ok ok ok ok ok ok
ok ok wait false illegal illegal illegal illegal
wait false wait false illegal illegal illegal illegal
illegal illegal illegal illegal ok ok wait false
illegal illegal illegal illegal wait false wait false
- 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
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.
Optional string parameters which are passed to the driver.
The cdb, cdb_make, flatfile, inifile, qdbm and tcadb drivers do not support additional parameters.
The db1, db2, db3, db4, dbm, gdbm, and ndbm drivers supports a single additional parameter $filemode, which has the same meaning as the $mode parameter of chmod(), and defaults to 0644.
The lmdb driver accepts two additional parameters. The first allows to specify the $filemode (see description above), and the second to specify the $mapsize, where the value should be a multiple of the page size of the OS, or zero, to use the default mapsize. The $mapsize parameter is supported as of PHP 7.3.14 and 7.4.2, respectively.
Returns a positive handle on success 或者在失败时返回
|7.3.14, 7.4.2||The lmdb driver now supports an additional $mapsize parameter.|