PHP wrapper for DBA (dbm-style Database Abstraction) Functions

The DBA functions provide a single, uniform interface to a wide variety of dbm-style databases. In broad way you can think of dbm style databases as simple stored as key-value pairs.

It is not always necessary to use always RDBMS for database operations, dba will do perfectly fine for small data sets. Specailly I found dba useful when you are doing network trips just to fetch small chunk of data. Here DBA files can come handy, if need to summerize this , it is like

  1. create dba
  2. propagate it over network
  3. access it locally

I tried to develop a simple PHP DBA Wrapper, lets see how that can be used

The code above creates a database with name ‘programminglanguages’ and inserts few key and values. Following code snippet shows how we can access any key from dba

As you can see you need to specify mode while opening dba database. Following are most commonly used modes –

  • 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
  • n for create, truncate and read/write access.

Now here is the simple wrapper class –

We need to decide the handler while creating dba files, for e.g. db2, db4 etc. You can find out what handlers are available to you with php function dba_handlers

Hope this helps!

Add a Comment

Your email address will not be published. Required fields are marked *