php-doc-en/functions/dbm.xml
2001-12-12 20:47:43 +00:00

320 lines
9.4 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.15 $ -->
<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">
<![CDATA[
$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>
<funcprototype>
<funcdef>int <function>dbmopen</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
<paramdef>string <parameter>flags</parameter></paramdef>
</funcprototype>
</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>filename.db</filename> 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
<filename>.lck</filename> 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
<ulink url="&url.gdbm;">GNU's GDBM</ulink>.
</para>
&note.sm.uidcheck;
</refsect1>
</refentry>
<refentry id="function.dbmclose">
<refnamediv>
<refname>dbmclose</refname>
<refpurpose>Closes a dbm database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>dbmclose</function></funcdef>
<paramdef>int <parameter>dbm_identifier</parameter></paramdef>
</funcprototype>
</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>
<funcprototype>
<funcdef>bool <function>dbmexists</function></funcdef>
<paramdef>int <parameter>dbm_identifier</parameter></paramdef>
<paramdef>string <parameter>key</parameter></paramdef>
</funcprototype>
</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>
<funcprototype>
<funcdef>string <function>dbmfetch</function></funcdef>
<paramdef>int <parameter>dbm_identifier</parameter></paramdef>
<paramdef>string <parameter>key</parameter></paramdef>
</funcprototype>
</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>
<funcprototype>
<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>
</funcprototype>
</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>
<funcprototype>
<funcdef>int <function>dbmreplace</function></funcdef>
<paramdef>int <parameter>dbm_identifier</parameter></paramdef>
<paramdef>string <parameter>key</parameter></paramdef>
<paramdef>string <parameter>value</parameter></paramdef>
</funcprototype>
</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>
<funcprototype>
<funcdef>bool <function>dbmdelete</function></funcdef>
<paramdef>int <parameter>dbm_identifier</parameter></paramdef>
<paramdef>string <parameter>key</parameter></paramdef>
</funcprototype>
</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>
<funcprototype>
<funcdef>string <function>dbmfirstkey</function></funcdef>
<paramdef>int <parameter>dbm_identifier</parameter></paramdef>
</funcprototype>
</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>
<funcprototype>
<funcdef>string <function>dbmnextkey</function></funcdef>
<paramdef>int <parameter>dbm_identifier</parameter></paramdef>
<paramdef>string <parameter>key</parameter></paramdef>
</funcprototype>
</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 role="php">
<![CDATA[
$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>
<funcprototype>
<funcdef>string <function>dblist</function></funcdef>
<void/>
</funcprototype>
</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
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->