PHP: DBM Funkce [zastaral�] - Manual
PHP  
downloads | documentation | faq | getting help | mailing lists | | php.net sites | links | my php.net 
search for in the  
<dbase_replace_recorddblist>
view the version of this page
Last updated: Thu, 15 Jul 2004

XIX. DBM Funkce [zastaral�]

�vod

Tyto funkce v�m umo��uj� ukl�dat z�znamy do datab�z� typu dbm. Tento typ datab�z� (podporovan� Berkeley DB, GDBM, n�kter�mi syst�mov�mi knihovnami, a tak� vestav�nou flatfile knihovnou) ukl�d� kl��/hodnota p�ry (oproti plnohodnotn�m rela�n�m datab�z�m).

Pozn�mka: Podpora dbm je nicm�n� zavr�ena a doporu�ujeme v�m pou��t m�sto toho funkce datab�zov� abstrak�n� vrstvy (dbm-styl)

Po�adavky

K pou�it� tohoto roz���en� mus�te PHP zkompilovat s podporou pou�it� datab�ze. Viz seznam podporovan�ch datab�z�.

Instalace

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.

Konfigurace b�hu

Toto roz���en� nem� definov�no ��dn� konfigura�n� direktivy.

Typy prost�edk�

Funkce dbmopen() vrac� identifik�tor datab�ze, kter� pou��vaj� ostatn� dbm-funkce.

P�eddefinovan� konstanty

Toto roz���en� nem� definov�ny ��dn� konstanty.

P��klady

P��klad 1. DBM - p��klad

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

?>

Obsah
dblist -- Z�skat n�zev pou��van� DBM-kompatibiln� knihovny
dbmclose -- Zav��t dbm datab�zi
dbmdelete --  Smazat v DMB datab�zi hodnotu spojenou s ur�it�m kl��em
dbmexists --  Zjist�, jestli pro zadan� kl�� existuje v DBM datab�zi hodnota
dbmfetch --  Z�skat z DBM datab�ze hodnotu spojenou s ur�it�m kl��em
dbmfirstkey -- Z�skat z DBM datab�ze prvn� kl��
dbminsert --  Vlo�it do DBM datab�ze hodnotu a kl��
dbmnextkey -- Z�skat dal�� kl�� z DBM datab�ze
dbmopen -- Otev��t DBM datab�zi
dbmreplace --  Nahredit v DBM datab�zi hodnotu s ur�it�m kl��em


add a note add a note User Contributed Notes
DBM Funkce [zastaral�]
foripepe at yahoo dot com
28-Feb-2002 06: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);
jb at abzone dot cz
05-Oct-2001 05:27
NOTE: DBM and DBA are two different extensions which must
     be configured separately.

Hi *,
names of these functions was changed in PHP4.
Refer to
or .
Regards Jindra
mouse at bloodletting dot com
07-Jul-2001 01: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.

<dbase_replace_recorddblist>
 Last updated: Thu, 15 Jul 2004
show source | credits | sitemap | contact | advertising | mirror sites 
Copyright © 2001-2004 The PHP Group
All rights reserved.
This unofficial mirror is operated at: /
Last updated: Sun Nov 14 23:09:54 2004 Local time zone must be set--see zic manual page