Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : DBM Functions [deprecated]

DBM Functions [deprecated]

Introduction

These functions allow you to store records stored in a dbm-style database. This type of database (supported by the Berkeley DB, » GDBM, and some system libraries, as well as a built-in flatfile library) stores key/value pairs (as opposed to the full-blown records supported by relational databases).

Note:

DBM support is deprecated and you are encouraged to use the Database (dbm-style) abstraction layer functions instead.

Note:

This extension has been removed from PHP and is no longer available as of PHP 5.0.0.

Requirements

To use this functions you have to compile PHP with support for an underlying database. See the list of supported Databases.

Installation

In order to use these functions, you must compile PHP with dbm support by using the --with-db option. In addition you must ensure support for an underlying database or you can use some system libraries.

Runtime Configuration

This extension has no configuration directives defined in php.ini.

Resource Types

The function dbmopen() returns an database identifier which is used by the other dbm-functions.

Predefined Constants

This extension has no constants defined.

Examples

Example 484. DBM example

<?php

$dbm
= dbmopen("lastseen", "w");
if (
dbmexists($dbm, $userid)) {
   
$last_seen = dbmfetch($dbm, $userid);
} else {
   
dbminsert($dbm, $userid, time());
}
do_stuff();
dbmreplace($dbm, $userid, time());
dbmclose($dbm);

?>


Table of Contents

dblist — Describes the DBM-compatible library being used
dbmclose — Closes a dbm database
dbmdelete — Deletes the value for a key from a DBM database
dbmexists — Tells if a value exists for a key in a DBM database
dbmfetch — Fetches a value for a key from a DBM database
dbmfirstkey — Retrieves the first key from a DBM database
dbminsert — Inserts a value for a key in a DBM database
dbmnextkey
dbmopen — Opens a DBM database
dbmreplace — Replaces the value for a key in a DBM database

Code Examples / Notes » ref.dbm

jb

NOTE: DBM and DBA are two different extensions which must
     be configured separately.
Hi *,
names of these functions was changed in PHP4.
Refer to http://www.faqts.com/knowledge_base/view.phtml/aid/1988
or http://www.zend.com/manual/ref.dba.php .
Regards Jindra


foripepe

First:
Make a firstdbm.db file.
Set attribute Read and Write.
--------------------------------------
<html><body>
<?
$dbm = dbmopen("firstdbm","w");
echo "<b>\$dbm: $dbm = dbmopen(\"firstdbm\", \"w\");</b>< br>";
echo "<i>".dblist()." = dblist();</i>< br>< br>";
$fruit = "apple";
$colour = "red";
if (dbmexists ($dbm, $fruit)) {
 $colour = dbmfetch ($dbm, $fruit);
 echo "\$colour: $colour = dbmfetch(\$dbm: $dbm, \$fruit: $fruit);< br>";
 $key = dbmreplace($dbm, $fruit, "green");
 echo "\$key: $key = dbmreplace(\$dbm: $dbm, \$fruit: $fruit, \"green\");< br>";
 $colour = dbmfetch ($dbm, $fruit);
 echo "\$colour: $colour = dbmfetch(\$dbm: $dbm, \$fruit: $fruit);< br>";
 if ( !dbmdelete($dbm, $fruit) ) {
   echo "False (OK) = dbmdelete(\$dbm: $dbm, \$fruit: $fruit);< br>";
 } else {
   echo "True (NOT OK) = dbmdelete(\$dbm: $dbm, \$fruit: $fruit);< br>";
 }
 $colour = dbmfetch ($dbm, $fruit);
 echo "\$color: $colour = dbmfetch(\$dbm: $dbm, \$fruit: $fruit);< br><hr>";
 $i = 1;
 $key = dbmfirstkey($dbm);
 while ($key) {
   if ($i==1) {
     echo "\$key: $key = dbmfirstkey(\$dbm: $dbm);< br>";
   } else {
     echo "\$key: $key = dbmnextkey(\$dbm: $dbm);< br>";
   }
   $i++;
   $colour = dbmfetch ($dbm, $key);
   echo "\$colour: $colour = dbmfetch(\$dbm: $dbm, \$key: $key);< br>";
   $key = dbmnextkey($dbm,$key);
 }
} else {
 dbminsert ($dbm, $fruit, $colour);
 echo "dbminsert(\$dbm: $dbm, \$fruit: $fruit, \$colour: $colour);< br>";
 dbminsert ($dbm, "pear", "yellow");
 echo "dbminsert(\$dbm: $dbm, \"pear\", \"yellow\");< br>";
 dbminsert ($dbm, "apricot", "pink");
 echo "dbminsert(\$dbm: $dbm, \"apricot\", \"pink\");< br><hr>";
 $i = 1;
 $key = dbmfirstkey($dbm);
 while ($key) {
   if ($i==1) {
     echo "\$key: $key = dbmfirstkey(\$dbm: $dbm);< br>";
   } else {
     echo "\$key: $key = dbmnextkey(\$dbm: $dbm);< br>";
   }
   $i++;
   $colour = dbmfetch ($dbm, $key);
   echo "\$colour: $colour = dbmfetch(\$dbm: $dbm, \$key: $key);< br>";
   $key = dbmnextkey($dbm,$key);
 }
}
echo "< br>";
if (dbmclose ($dbm)) {
 echo "<b>True (OK) = dbmclose(\$dbm: $dbm);</b>< br>";
} else {
 echo "<b>False (NOT OK) = dbmclose(\$dbm: $dbm);</b>< br>";
};
?>
</body></html>
--------------------------------------
The first run output:
$dbm: 1 = dbmopen("firstdbm", "w");
ndbm support enabled = dblist();
dbminsert($dbm: 1, $fruit: apple, $colour: red);
dbminsert($dbm: 1, "pear", "yellow");
dbminsert($dbm: 1, "apricot", "pink");
$key: pear = dbmfirstkey($dbm: 1);
$colour: yellow = dbmfetch($dbm: 1, $key: pear);
$key: apricot = dbmnextkey($dbm: 1);
$colour: pink = dbmfetch($dbm: 1, $key: apricot);
$key: apple = dbmnextkey($dbm: 1);
$colour: red = dbmfetch($dbm: 1, $key: apple);
True (OK) = dbmclose($dbm: 1);
--------------------------------------
The second run output:
$dbm: 1 = dbmopen("firstdbm", "w");
ndbm support enabled = dblist();
$colour: red = dbmfetch($dbm: 1, $fruit: apple);
$key: 0 = dbmreplace($dbm: 1, $fruit: apple, "green");
$colour: green = dbmfetch($dbm: 1, $fruit: apple);
False (OK) = dbmdelete($dbm: 1, $fruit: apple);
$color: = dbmfetch($dbm: 1, $fruit: apple);
$key: pear = dbmfirstkey($dbm: 1);
$colour: yellow = dbmfetch($dbm: 1, $key: pear);
$key: apricot = dbmnextkey($dbm: 1);
$colour: pink = dbmfetch($dbm: 1, $key: apricot);
True (OK) = dbmclose($dbm: 1);


mouse

Be advised that almost every function in this section either has no documentation or incorrectly documented regarding return codes.  If you want to use the DB methods safely you will have to reverse engineer the return codes and hope that they do not change values returned by the functions in the future to match the incorrect documentation.
In my experience, the return code of 0 or FALSE indicates no error.  This matches the behavior of GDBM which I am using as my underlying DB manager.  This may not be true for people using another manager, or the builtin flatfile code.


Change Language


Follow Navioo On Twitter
.NET Functions
Apache-specific Functions
Alternative PHP Cache
Advanced PHP debugger
Array Functions
Aspell functions [deprecated]
BBCode Functions
BCMath Arbitrary Precision Mathematics Functions
PHP bytecode Compiler
Bzip2 Compression Functions
Calendar Functions
CCVS API Functions [deprecated]
Class/Object Functions
Classkit Functions
ClibPDF Functions [deprecated]
COM and .Net (Windows)
Crack Functions
Character Type Functions
CURL
Cybercash Payment Functions
Credit Mutuel CyberMUT functions
Cyrus IMAP administration Functions
Date and Time Functions
DB++ Functions
Database (dbm-style) Abstraction Layer Functions
dBase Functions
DBM Functions [deprecated]
dbx Functions
Direct IO Functions
Directory Functions
DOM Functions
DOM XML Functions
enchant Functions
Error Handling and Logging Functions
Exif Functions
Expect Functions
File Alteration Monitor Functions
Forms Data Format Functions
Fileinfo Functions
filePro Functions
Filesystem Functions
Filter Functions
Firebird/InterBase Functions
Firebird/Interbase Functions (PDO_FIREBIRD)
FriBiDi Functions
FrontBase Functions
FTP Functions
Function Handling Functions
GeoIP Functions
Gettext Functions
GMP Functions
gnupg Functions
Net_Gopher
Haru PDF Functions
hash Functions
HTTP
Hyperwave Functions
Hyperwave API Functions
i18n Functions
IBM Functions (PDO_IBM)
IBM DB2
iconv Functions
ID3 Functions
IIS Administration Functions
Image Functions
Imagick Image Library
IMAP
Informix Functions
Informix Functions (PDO_INFORMIX)
Ingres II Functions
IRC Gateway Functions
PHP / Java Integration
JSON Functions
KADM5
LDAP Functions
libxml Functions
Lotus Notes Functions
LZF Functions
Mail Functions
Mailparse Functions
Mathematical Functions
MaxDB PHP Extension
MCAL Functions
Mcrypt Encryption Functions
MCVE (Monetra) Payment Functions
Memcache Functions
Mhash Functions
Mimetype Functions
Ming functions for Flash
Miscellaneous Functions
mnoGoSearch Functions
Microsoft SQL Server Functions
Microsoft SQL Server and Sybase Functions (PDO_DBLIB)
Mohawk Software Session Handler Functions
mSQL Functions
Multibyte String Functions
muscat Functions
MySQL Functions
MySQL Functions (PDO_MYSQL)
MySQL Improved Extension
Ncurses Terminal Screen Control Functions
Network Functions
Newt Functions
NSAPI-specific Functions
Object Aggregation/Composition Functions
Object property and method call overloading
Oracle Functions
ODBC Functions (Unified)
ODBC and DB2 Functions (PDO_ODBC)
oggvorbis
OpenAL Audio Bindings
OpenSSL Functions
Oracle Functions [deprecated]
Oracle Functions (PDO_OCI)
Output Control Functions
Ovrimos SQL Functions
Paradox File Access
Parsekit Functions
Process Control Functions
Regular Expression Functions (Perl-Compatible)
PDF Functions
PDO Functions
Phar archive stream and classes
PHP Options&Information
POSIX Functions
Regular Expression Functions (POSIX Extended)
PostgreSQL Functions
PostgreSQL Functions (PDO_PGSQL)
Printer Functions
Program Execution Functions
PostScript document creation
Pspell Functions
qtdom Functions
Radius
Rar Functions
GNU Readline
GNU Recode Functions
RPM Header Reading Functions
runkit Functions
SAM - Simple Asynchronous Messaging
Satellite CORBA client extension [deprecated]
SCA Functions
SDO Functions
SDO XML Data Access Service Functions
SDO Relational Data Access Service Functions
Semaphore
SESAM Database Functions
PostgreSQL Session Save Handler
Session Handling Functions
Shared Memory Functions
SimpleXML functions
SNMP Functions
SOAP Functions
Socket Functions
Standard PHP Library (SPL) Functions
SQLite Functions
SQLite Functions (PDO_SQLITE)
Secure Shell2 Functions
Statistics Functions
Stream Functions
String Functions
Subversion Functions
Shockwave Flash Functions
Swish Functions
Sybase Functions
TCP Wrappers Functions
Tidy Functions
Tokenizer Functions
Unicode Functions
URL Functions
Variable Handling Functions
Verisign Payflow Pro Functions
vpopmail Functions
W32api Functions
WDDX Functions
win32ps Functions
win32service Functions
xattr Functions
xdiff Functions
XML Parser Functions
XML-RPC Functions
XMLReader functions
XMLWriter Functions
XSL functions
XSLT Functions
YAZ Functions
YP/NIS Functions
Zip File Functions
Zlib Compression Functions
eXTReMe Tracker