Team LiB
Previous Section Next Section

Preparations and Settings

Installation of the dba extension is rather easy. As always, Windows users have an easy job. The ext subdirectory of the PHP installation contains the module in binary, compiled form: the file php_dba.dll. The following entry in php.ini does the trick:


Under Unix, Linux, and Mac, the configuration switch --enable-dba=shared creates a shared module.

Then you have to decide which of the available database handlers you would like to use with PHP's dba functions. Each of these handler has its advantages and disadvantages, and not every handler works on every system, so PHP loses a bit of its portability here. A possibility exists that the handler we are using in the sample code in this chapter does not work on your specific system. To make these scripts more portable, we have created an include file with the content from Listing 26.1:

Listing 26.1. The Include File for the dba Handler Used
  $dbahandler = "flatfile";

In all scripts, this file is included so that the variable $dbahandler contains the name of the used handler:

require_once "";

This way, you have to change only one file to make all examples work on your machine.

Table 26.1 shows a complete list of all available dba handlers.

Table 26.1. Available dba Handlers

Handler Name


Configuration Switch


Handler for cdb available at Only reading and writing is supported, no updating.



Handler for cdb available at Only creating a database is supported.



Handler for Sleepycat Software's DB2.Does not work with db3 and db4



Handler for Sleepycat Software's DB3.Does not work with db2 and db4.



Handler for Sleepycat Software's DB4.Does not work with db2 and db3.



The original Berkeley Style DB format.Use not encouraged anymore.



Flat-file format.Lowest common denominator.



GNU database manager.



INI file format (from Windows 3.x) Can be used to work with php.ini.



"New" version of dbm.Better than dgm, but still use not encouraged anymore.



qdbm format available at Does not work with dbm and gdbm.


Unix, Linux, and Mac users have to install at least one of those formats to use PHP's dba functions. Windows users who work with the precompiled PHP binaries have to use what the system offers them; as of time of writing, the supported dba handlers are cdb (and cdb_make), db3, inifile, and flatfile. Figure 26.1 shows a part of the output of phpinfo(): The installation was successful.

Figure 26.1. Success: The dba functions are available.


A quite naïve, but still promising, approach to automatically detect a suitable handler for the dba handler is to use the PHP function dba_handlers() that returns an array of all supported handlers. This code will work as long as at least one handler is available:

$dbahandler = (dba_handlers())[0];

On the other hand, the flatfile handler works on every system; however, it is not the optimal choice because of performance issues.

    Team LiB
    Previous Section Next Section