Database (dbm-style) abstraction layer functions dba These functions build the foundation for accessing Berkeley DB style databases. This is a general abstraction layer for several file-based databases. As such, functionality is limited to a subset of features modern databases such as Sleepycat Software's DB2 support. (This is not to be confused with IBM's DB2 software, which is supported through the ODBC functions.) The behaviour of various aspects depend on the implementation of the underlying database. Functions such as dba_optimize and dba_sync will do what they promise for one database and will do nothing for others. The following handlers are supported: dbm is the oldest (original) type of Berkeley DB style databases. You should avoid it, if possible. We do not support the compatibility functions built into DB2 and gdbm, because they are only compatible on the source code level, but cannot handle the original dbm format. ndbm is a newer type and more flexible than dbm. It still has most of the arbitrary limits of dbm (therefore it is deprecated). gdbm is the GNU database manager. db2 is Sleepycat Software's DB2. It is described as "a programmatic toolkit that provides high-performance built-in database support for both standalone and client/server applications." cdb is "a fast, reliable, lightweight package for creating and reading constant databases." It is from the author of qmail and can be found here. Since it is constant, we support only reading operations. DBA example <?php $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 is binary safe and does not have any arbitrary limits. It inherits all limits set by the underlying database implementation. All file-based databases must provide a way of setting the file mode of a new created database, if that is possible at all. The file mode is commonly passed as the fourth argument to dba_open or dba_popen. You can access all entries of a database in a linear way by using the dba_firstkey and dba_nextkey functions. You may not change the database while traversing it. Traversing a database <?php # ...open database... $key = dba_firstkey($id); while($key != false) { if(...) { # remember the key to perform some action later $handle_later[] = $key; } $key = dba_nextkey($id); } for($i = 0; $i < count($handle_later); $i++) dba_delete($handle_later[$i], $id); ?> dba_close Close database Description void dba_close int handle dba_close closes the established database and frees all resources specified by handle. handle is a database handle returned by dba_open. dba_close does not return any value. See also: dba_open dba_popen dba_delete Delete entry specified by key Description string dba_delete string key int handle dba_delete deletes the entry specified by key from the database specified with handle. key is the key of the entry which is deleted. handle is a database handle returned by dba_open. dba_delete returns true or false, if the entry is deleted or not deleted, respectively. See also: dba_exists dba_fetch dba_insert dba_replace dba_exists Check whether key exists Description bool dba_exists string key int handle dba_exists checks whether the specified key exists in the database specified by handle. key is the key the check is performed for. handle is a database handle returned by dba_open. dba_exists returns true or false, if the key is found or not found, respectively. See also: dba_fetch dba_delete dba_insert dba_replace dba_fetch Fetch data specified by key Description string dba_fetch string key int handle dba_fetch fetches the data specified by key from the database specified with handle. key is the key the data is specified by. handle is a database handle returned by dba_open. dba_fetch returns the associated string or false, if the key/data pair is found or not found, respectively. See also: dba_exists dba_delete dba_insert dba_replace dba_firstkey Fetch first key Description string dba_firstkey int handle dba_firstkey returns the first key of the database specified by handle and resets the internal key pointer. This permits a linear search through the whole database. handle is a database handle returned by dba_open. dba_firstkey returns the key or false depending on whether it succeeds or fails, respectively. See also: dba_nextkey dba_insert Insert entry Description bool dba_insert string key string value int handle dba_insert inserts the entry described with key and value into the database specified by handle. It fails, if an entry with the same key already exists. key is the key of the entry to be inserted. value is the value to be inserted. handle is a database handle returned by dba_open. dba_insert returns true or false, depending on whether it succeeds of fails, respectively. See also: dba_exists dba_delete dba_fetch dba_replace dba_nextkey Fetch next key Description string dba_nextkey int handle dba_nextkey returns the next key of the database specified by handle and increments the internal key pointer. handle is a database handle returned by dba_open. dba_nextkey returns the key or false depending on whether it succeeds or fails, respectively. See also: dba_firstkey dba_popen Open database persistently Description int dba_popen string path string mode string handler ... dba_popen establishes a persistent database instance for path with mode using handler. path is commonly a regular path in your filesystem. mode 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. handler is the name of the handler which shall be used for accessing path. It is passed all optional parameters given to dba_popen and can act on behalf of them. dba_popen returns a positive handler id or false, in the case the open is successful or fails, respectively. See also: dba_open dba_close dba_open Open database Description int dba_open string path string mode string handler ... dba_open establishes a database instance for path with mode using handler. path is commonly a regular path in your filesystem. mode 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. handler is 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 returns a positive handler id or false, in the case the open is successful or fails, respectively. See also: dba_popen dba_close dba_optimize Optimize database Description bool dba_optimize int handle dba_optimize optimizes the underlying database specified by handle. handle is a database handle returned by dba_open. dba_optimize returns true or false, if the optimization succeeds or fails, respectively. See also: dba_sync dba_replace Replace or insert entry Description bool dba_replace string key string value int handle dba_replace replaces or inserts the entry described with key and value into the database specified by handle. key is the key of the entry to be inserted. value is the value to be inserted. handle is a database handle returned by dba_open. dba_replace returns true or false, depending on whether it succeeds of fails, respectively. See also: dba_exists dba_delete dba_fetch dba_insert dba_sync Synchronize database Description bool dba_sync int handle dba_sync synchronizes the database specified by handle. This will probably trigger a physical write to disk, if supported. handle is a database handle returned by dba_open. dba_sync returns true or false, if the synchronization succeeds or fails, respectively. See also: dba_optimize