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:

 extension=php_dba.dll 

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 handler.inc.php with the content from Listing 26.1:

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

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

 require_once "handler.inc.php"; 

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

Description

Configuration Switch

cdb

Handler for cdb available at http://cr.yp.to/cdb.html. Only reading and writing is supported, no updating.

--with-cdb

cdb_make

Handler for cdb available at http://cr.yp.to/cdb.html. Only creating a database is supported.

--with-cdb

db2

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

--with-db2=/path/to/db2

db3

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

--with-db3=/path/to/db3

db4

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

--with-db4=/path/to/db4

dbm

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

--with-dbm=/path/to/dbm

flatfile

Flat-file format.Lowest common denominator.

--with-flatfile

gdbm

GNU database manager.

--with-gdbm=/path/to/gdbm

inifile

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

--with-inifile

ndbm

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

--with-ndbm=/path/to/ndbm

qdbm

qdbm format available at http://qdbm.sf.net/ Does not work with dbm and gdbm.

--with-qdbm=/path/to/qdbm


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.


TIP

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.




PHP 5 Unleashed
PHP 5 Unleashed
ISBN: 067232511X
EAN: 2147483647
Year: 2004
Pages: 257

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net