PHP: DBM Functions - Manual
PHP  
downloads | documentation | faq | getting help | | php.net sites | links 
search for in the  
previousdbase_replace_recorddblistnext
Last updated: Tue, 09 Jul 2002
view this page in Printer friendly version | English | Brazilian Portuguese | Czech | Dutch | Finnish | French | German | Italian | Japanese | Korean | Polish | Romanian | Russian | Spanish | Turkish

XX. DBM Functions

Bevezet�s

These functions allow you to store records stored in a dbm-style database. This type of database (supported by the Berkeley DB, , 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).

Megjegyz�s: However, dbm support is deprecated and you are encourged to use the Database (dbm-style) abstraction layer functions instead.

K�vetelm�nyek

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

Telep�t�s

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

Fut�sidej� be�ll�t�sok

Ez a kiterjeszt�s semmilyen konfigur�ci�s be�ll�t�sokat nem defini�l.

Er�forr�s t�pusok

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

El�re defini�lt �lland�k

Ez a kiterjeszt�s semmilyen konstans �rt�ket nem defini�l.

P�ld�k

P�lda 1. DBM example

$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);

Tartalom
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 --  Retrieves the next key from a DBM database
dbmopen -- Opens a DBM database
dbmreplace --  Replaces the value for a key in a DBM database
User Contributed Notes
DBM Functions
add a note about notes

25-Apr-2000 09:00

You may need to add (or uncomment) the line
"extension=php3_dbm.dll" line in php3.ini in your Windows
directory.


12-Aug-2000 04:51

actually you only need to put in that line if you want it globally included
in all scripts, otherwise you can just put: use(dbm.o); in your script.


15-Feb-2001 02:48

just add the php_db.dll extension and it works


07-Jul-2001 12:23

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.


05-Oct-2001 04:27

Hi *,
names of these functions was changed in PHP4.
Refer to 

or 
.
Regards Jindra


28-Feb-2002 04:16

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);

add a note about notes
previousdbase_replace_recorddblistnext
Last updated: Tue, 09 Jul 2002
show source | credits | stats | mirror sites:  
Copyright © 2001, 2002 The PHP Group
All rights reserved.
This mirror generously provided by:
Last updated: Thu Jul 11 00:19:09 2002 CEST