What is PhpDig?
PhpDig is a PHP MySQL based
Web Spider & Search Engine.



dba_open — Opens a connection to a dbm-style database.


mixed dba_open(path, mode, database_flavor[, . . .]);
string path: Path to the db file
string mode: Mode in which to open the database
string database_flavor: Type of dbm-style database to use
mixed . . . (optional): Optional parameters


A resource handle on success; FALSE on failure


dba_open() opens a connection to a db file.

The function takes three or more arguments. The first argument is the path to the db file. The path can be relative or absolute.

The second argument contains a single-character mnemonic indicating in which mode to open the file. The following table lists the valid modes.

Mnemonic Mode Description
c Create Full read/write access to a db file. If the file doesn't exist, try to create it.
n New Full read/write access to a db file. Create a new db file. If the file exists, truncate it.
r Read Read-only access to a file. If the file doesn't exist, fail.
w Write Write-only access to a file. If the file doesn't exist, fail.

The third argument contains the flavor of dbm-style database to use. Valid types include cdb, db2, db3, dbm, gdbm, and ndbm.


Each of these dbm-style databases needs to be separately installed if you want to use them with the dba functions. See the beginning of this chapter for information on where to download the various databases.

The fourth and subsequent arguments can be used to pass extra parameters directly to the database that's being used to open the db file.


PHP Version: 3.0.8+, 4.0b2+

See also



Example 218. Open a connection to any dbm files in a given directory and search the contents

$dir = '.';

$dir_handle = opendir ($dir)
    or die ("Could not open directory <i>$dir</i>.");

while ($entry = readdir ($dir_handle)) {
    $entry = $dir . '/' . $entry;

    if (is_dir ($entry) and substr ($entry, 0, -4) == '.dbm')
        $dbm_list[] = $entry;

foreach ($dbm_list as $dbm_file) {
    // Use the @ to ignore failed open attempts
    $dba_handle = @ dba_open ($dbm_file, 'r', 'gdbm');
    $key = dba_firstkey ($dba_handle);

    if ($key !== FALSE) {
        echo "<br><br>DBM FILE: $dbm_file<br>";
        while ($key !== FALSE) {
            printf ("%-'.16s..%'.16s<br>", "<b>$key</b>", dba_fetch ($key, $dba_handle));
            $key = dba_nextkey ($dba_handle);

PHP Functions Essential Reference. Copyright © 2002 by New Riders Publishing (Authors: Zak Greant, Graeme Merrall, Torben Wilson, Brett Michlitsch). This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at The authors of this book have elected not to choose any options under the OPL. This online book was obtained from and is designed to provide information about the PHP programming language, focusing on PHP version 4.0.4 for the most part. The information is provided on an as-is basis, and no warranty or fitness is implied. All persons and entities shall have neither liability nor responsibility to any person or entity with respect to any loss or damage arising from the information contained in this book.

Powered by: vBulletin Version 3.0.7
Copyright ©2000 - 2005, Jelsoft Enterprises Ltd.
Copyright © 2001 - 2005, ThinkDing LLC. All Rights Reserved.