dba_open
(PHP 4, PHP 5, PHP 7, PHP 8)
Open database
Description
dba_open() establishes a database instance for path with mode using handler.
Parameters
pathCommonly a regular path in your filesystem.
modeIt is
rfor 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. Use
lto 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 add
tas 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.NoteThere 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:
already open mode= "rl"mode= "rlt"mode= "wl"mode= "wlt"mode= "rd"mode= "rdt"mode= "wd"mode= "wdt"not open ok ok ok ok ok ok ok ok mode= "rl"ok ok wait false illegal illegal illegal illegal mode= "wl"wait false wait false illegal illegal illegal illegal mode= "rd"illegal illegal illegal illegal ok ok wait false mode= "wd"illegal illegal illegal illegal wait false wait false - ok: the second call will be successful.
- 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 formodeparameter.
handlerThe name of the handler which shall be used for accessing
path. It is passed all optional parameters given todba_open()and can act on behalf of them. Ifhandleris null, then the default handler is invoked.permissionOptional Integer parameter which is passed to the driver. It has the same meaning as the
permissionsparameter ofchmod(), and defaults to0644.The
db1,db2,db3,db4,dbm,gdbm,ndbm, andlmdbdrivers support thepermissionparameter.map_sizeOptional Integer parameter which is passed to the driver. Its value should be a multiple of the page size of the OS, or zero, to use the default map size.
Only the
lmdbdriver accepts themap_sizeparameter.flagsFlags to pass to the database drivers. If null the default flags will be provided. Currently, only the LMDB driver supports the following flags
DBA_LMDB_USE_SUB_DIRandDBA_LMDB_NO_SUB_DIR.
Return Values
Returns a Dba\Connection instance on successFalseforfailure.
Errors/Exceptions
false is returned and an E_WARNING level error is issued when handler is null, but there is no default handler.
Changelog
| Version | Description |
|---|---|
| 8.4.0 | Returns a Dba\Connection instance now; previously, a Resource was returned. |
| 8.2.0 | flags is added. |
| 8.2.0 | handler is now nullable. |
| 7.3.14, 7.4.2 | The lmdb driver now supports an additional map_size parameter. |