PhpDig.net

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




dba_popen

Name

dba_popen — Opens a persistent connection to a db file.

Synopsis

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

Returns

A resource handle on success; FALSE on failure.

Description

dba_popen() opens a persistent connection to a db file. In this case, persistent means that the connection can remain open after the PHP script exits. This allows the connection to be reused, instead of going through the full process of opening, using, and then closing for every invocation of the script.

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.

Note

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.

Version

PHP Version: 3.0.8+, 4.0b2+

See also

dba_open()

Example

Example 217. Open a persistent read-only connection

$db_file = 'state.dbm';
$db_mode = 'r';
$db_handler = 'gdbm';

$dba_handle = dba_popen ($db_file, $db_mode, $db_handler)
    or die ("A persistent connection to <i>$db_file</i> could not be made 
        using connection mode <i>$db_mode</i> and handler <i>$db_handler</i>");



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 http://www.opencontent.org/openpub/). The authors of this book have elected not to choose any options under the OPL. This online book was obtained from http://www.fooassociates.com/phpfer/ 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.