php-doc-en/functions/dbm.sgml
cslawi 9256eb3b12 Normalized according to the DocBook 3.1 DTD. This mostly just adds
closing tags and attribute quotes, but lets a stock 3.1 install
compile the PHP docs. It still compiles with DocBook 3.0, as well.


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@14693 c90b9560-bf6c-de11-be94-00142212c4b1
1999-10-20 22:41:42 +00:00

254 lines
8.5 KiB
Text

<reference id="ref.dbm">
<title>dbm functions</title>
<titleabbrev>DBM</titleabbrev>
<partintro>
<simpara>
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).</simpara>
<para>
<example>
<title>dbm example</title>
<programlisting role="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);
</programlisting></example>
</para>
</partintro>
<refentry id="function.dbmopen">
<refnamediv>
<refname>dbmopen</refname>
<refpurpose>opens a dbm database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>int <function>dbmopen</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
<paramdef>string <parameter>flags</parameter></paramdef>
</funcsynopsis>
<para>
The first argument is the full-path filename of the dbm file to be opened
and the second is the file open mode which is one of "r", "n", "c" or "w"
for read-only, new (implies read-write, and most likely will truncate an
already-existing database of the same name), create (implies read-write,
and will not truncate an already-existing database of the same name)
and read-write respectively.</para>
<para>
Returns an identifer to be passed to the other dbm functions on success,
or false on failure.</para>
<para>
If ndbm support is used, ndbm will actually create filename.dir and
filename.pag files. gdbm only uses one file, as does the internal flat-file
support, and Berkeley db creates a filename.db file. Note that PHP does its
own file locking in addition to any file locking that may be done by the dbm
library itself. PHP does not delete the .lck files it creates. It uses these
files simply as fixed inodes on which to do the file locking. For more
information on dbm files, see your Unix man pages, or obtain GNU's gdbm from
<filename role="url">ftp://prep.ai.mit.edu/pub/gnu</filename>.</para>
</refsect1>
</refentry>
<refentry id="function.dbmclose">
<refnamediv>
<refname>dbmclose</refname>
<refpurpose>closes a dbm database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>bool <function>dbmclose</function></funcdef>
<paramdef>int <parameter>dbm_identifier</parameter></paramdef>
</funcsynopsis>
<para>
Unlocks and closes the specified database.</para>
</refsect1>
</refentry>
<refentry id="function.dbmexists">
<refnamediv>
<refname>dbmexists</refname>
<refpurpose>tells if a value exists for a key in a dbm database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>bool <function>dbmexists</function></funcdef>
<paramdef>int <parameter>dbm_identifier</parameter></paramdef>
<paramdef>string <parameter>key</parameter></paramdef>
</funcsynopsis>
<para>
Returns true if there is a value associated with the <parameter>key</parameter>.</para>
</refsect1>
</refentry>
<refentry id="function.dbmfetch">
<refnamediv>
<refname>dbmfetch</refname>
<refpurpose>fetches a value for a key from a dbm database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>string <function>dbmfetch</function></funcdef>
<paramdef>int <parameter>dbm_identifier</parameter></paramdef>
<paramdef>string <parameter>key</parameter></paramdef>
</funcsynopsis>
<para>
Returns the value associated with <parameter>key</parameter>.</para>
</refsect1>
</refentry>
<refentry id="function.dbminsert">
<refnamediv>
<refname>dbminsert</refname>
<refpurpose>inserts a value for a key in a dbm database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>int <function>dbminsert</function></funcdef>
<paramdef>int <parameter>dbm_identifier</parameter></paramdef>
<paramdef>string <parameter>key</parameter></paramdef>
<paramdef>string <parameter>value</parameter></paramdef>
</funcsynopsis>
<para>
Adds the value to the database with the specified key.</para>
<para>
Returns -1 if the database was opened read-only, 0 if the insert
was successful, and 1 if the specified key already exists. (To replace
the value, use <function>dbmreplace</function>.)</para>
</refsect1>
</refentry>
<refentry id="function.dbmreplace">
<refnamediv>
<refname>dbmreplace</refname>
<refpurpose>replaces the value for a key in a dbm database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>bool <function>dbmreplace</function></funcdef>
<paramdef>int <parameter>dbm_identifier</parameter></paramdef>
<paramdef>string <parameter>key</parameter></paramdef>
<paramdef>string <parameter>value</parameter></paramdef>
</funcsynopsis>
<para>
Replaces the value for the specified key in the database.</para>
<para>
This will also add the key to the database if it didn't already
exist.</para>
</refsect1>
</refentry>
<refentry id="function.dbmdelete">
<refnamediv>
<refname>dbmdelete</refname>
<refpurpose>deletes the value for a key from a dbm database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>bool <function>dbmdelete</function></funcdef>
<paramdef>int <parameter>dbm_identifier</parameter></paramdef>
<paramdef>string <parameter>key</parameter></paramdef>
</funcsynopsis>
<para>
Deletes the value for <parameter>key</parameter> in the database.</para>
<para>
Returns false if the key didn't exist in the database.</para>
</refsect1>
</refentry>
<refentry id="function.dbmfirstkey">
<refnamediv>
<refname>dbmfirstkey</refname>
<refpurpose>retrieves the first key from a dbm database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>string <function>dbmfirstkey</function></funcdef>
<paramdef>int <parameter>dbm_identifier</parameter></paramdef>
</funcsynopsis>
<para>
Returns the first key in the database. Note that no particular order
is guaranteed since the database may be built using a hash-table,
which doesn't guarantee any ordering.</para>
</refsect1>
</refentry>
<refentry id="function.dbmnextkey">
<refnamediv>
<refname>dbmnextkey</refname>
<refpurpose>retrieves the next key from a dbm database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>string <function>dbmnextkey</function></funcdef>
<paramdef>int <parameter>dbm_identifier</parameter></paramdef>
<paramdef>string <parameter>key</parameter></paramdef>
</funcsynopsis>
<para>
Returns the next key after <parameter>key</parameter>. By calling
<function>dbmfirstkey</function> followed by successive
calls to <function>dbmnextkey</function> it is possible to
visit every key/value pair in the dbm database. For example:
<example>
<title>Visiting every key/value pair in a dbm database.</title>
<programlisting>
$key = dbmfirstkey($dbm_id);
while ($key) {
echo "$key = " . dbmfetch($dbm_id, $key) . "\n";
$key = dbmnextkey($dbm_id, $key);
}
</programlisting>
</example></para>
</refsect1>
</refentry>
<refentry id="function.dblist">
<refnamediv>
<refname>dblist</refname>
<refpurpose>describes the dbm-compatible library being used</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>string <function>dblist</function></funcdef>
<paramdef>void</paramdef>
</funcsynopsis>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->