Documentation » API Reference

Application:

Class: BDB

  • Package: saf.Database
  • Author: John Luxford <lux@simian.ca>
  • Copyright: Copyright (C) 2001-2003, Simian Systems Inc.
  • License: http://www.sitellite.org/index/license Simian Open Software License
  • Version: 1.0, 2001-10-22, $Id: BDB.php,v 1.3 2007/10/06 00:06:30 lux Exp $
  • Access: public

BDB is a very minimal wrapper around the Berkeley Database functions
in PHP. Its purpose is simply to create an object oriented interface
to those functions.


Usage Example


<?php

$bdb 
= new BDB ('/tmp/object_store.db''w''db3'0);

if (
$bdb->exists ($cgi->key)) {
    echo 
$bdb->fetch ($cgi->key);
}

$bdb->close ();

?>

Return to Top



Properties


$connection

  • Access: public

This is a Berkeley Database connection resource returned
by the dba_open () or dba_popen () function.


$path

  • Access: public

Path to the Berkeley Database.


$mode

  • Access: public

Mode to use when opening the database (corresponds to
the modes available to the dba_open () function.


$handler

  • Access: public

The database implementation used (db2, db3, gdbm, etc.).


$persistent

  • Access: public

Whether or not to use persistence when connecting to the database.

Return to Top



Methods


BDB ($path$mode 'r'$handler 'db3'$persistent 0

  • Access: public

Constructor Method. Establishes a connection to the database,
which can be verified by an if ($dbd->connection) {.


close () 

  • Access: public

Disconnects from the database.


delete ($key

  • Access: public
  • Return: boolean

Deletes a record from the database.


delete_all () 


exists ($key

  • Access: public
  • Return: boolean

Checks if a key/value pair exists in the database.


fetch ($key

  • Access: public
  • Return: string

Retrieves a value corresponding to the provided key, from
the database. Returns false on error.


firstkey () 

  • Access: public
  • Return: string

Retrieves the first key in the database.


insert ($key$value

  • Access: public
  • Return: boolean

Insert a new key/value pair into the database.


nextkey () 

  • Access: public
  • Return: string

Retrieves the next key in the database. Used with firstkey to
loop through records.


optimize () 

  • Access: public
  • Return: boolean

Optimizes the database.


replace ($key$value

  • Access: public
  • Return: boolean

Replaces the value of an existing pair with the new value
provided.


sync () 

  • Access: public
  • Return: boolean

Synchronizes the database. This usually writes the database
to disk.

Return to Top