Sophie

Sophie

distrib > Mandriva > 9.1 > ppc > media > main > by-pkgid > 0afeee9cca140e167a996902b9a677c5 > files > 3062

php-manual-en-4.3.0-2mdk.noarch.rpm

<HTML
><HEAD
><TITLE
>Database (dbm-style) abstraction layer functions</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="PHP Manual"
HREF="index.html"><LINK
REL="UP"
TITLE="Function Reference"
HREF="funcref.html"><LINK
REL="PREVIOUS"
TITLE="ctype_xdigit"
HREF="function.ctype-xdigit.html"><LINK
REL="NEXT"
TITLE="dba_close"
HREF="function.dba-close.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=ISO-8859-1"></HEAD
><BODY
CLASS="reference"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>PHP Manual</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.ctype-xdigit.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.dba-close.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="reference"
><A
NAME="ref.dba"
></A
><DIV
CLASS="TITLEPAGE"
><H1
CLASS="title"
>XVII. Database (dbm-style) abstraction layer functions</H1
><DIV
CLASS="PARTINTRO"
><A
NAME="AEN15724"
></A
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="dba.intro"
></A
>Introduction</H1
><P
>&#13;    These functions build the foundation for accessing Berkeley DB
    style databases.
   </P
><P
>&#13;    This is a general abstraction layer for several file-based databases.
    As such, functionality is limited to a common subset of features
    supported by modern databases such as
    <A
HREF="http://www.sleepycat.com/"
TARGET="_top"
>Sleepycat Software's DB2</A
>.
    (This is not to be confused with IBM's DB2 software, which is
    supported through the <A
HREF="ref.odbc.html"
>ODBC functions</A
>.)
   </P
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="dba.requirements"
></A
>Requirements</H1
><P
>&#13;     The behaviour of various aspects depends on the implementation of the
     underlying database. Functions such as <A
HREF="function.dba-optimize.html"
><B
CLASS="function"
>dba_optimize()</B
></A
>
     and <A
HREF="function.dba-sync.html"
><B
CLASS="function"
>dba_sync()</B
></A
> will do what they promise for one
     database and will do nothing for others. You have to download and install
     supported dba-Handlers.
    <DIV
CLASS="table"
><A
NAME="AEN15736"
></A
><P
><B
>Table 1. List of DBA handlers</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Handler</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Notes</TH
></TR
></THEAD
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="literal"
>dbm</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13;         Dbm is the oldest (original) type of Berkeley DB style
         databases. You should avoid it, if possible. We do not support
         the compatibility functions built into DB2 and gdbm, because
         they are only compatible on the source code level, but cannot
         handle the original dbm format.
        </TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="literal"
>ndbm</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13;         Ndbm is a newer type and more flexible than dbm. It still has
         most of the arbitrary limits of dbm (therefore it is
         deprecated).
        </TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="literal"
>gdbm</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13;         Gdbm is the <A
HREF="ftp://ftp.gnu.org/pub/gnu/gdbm/"
TARGET="_top"
>GNU database
         manager</A
>.
        </TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="literal"
>db2</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13;         DB2 is <A
HREF="http://www.sleepycat.com/"
TARGET="_top"
>Sleepycat Software's
         DB2</A
>. It is described as "a programmatic toolkit that
         provides high-performance built-in database support for both
         standalone and client/server applications.
        </TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="literal"
>db3</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13;         DB3 is <A
HREF="http://www.sleepycat.com/"
TARGET="_top"
>Sleepycat Software's
         DB3</A
>.
        </TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="literal"
>db4</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13;         DB4 is <A
HREF="http://www.sleepycat.com/"
TARGET="_top"
>Sleepycat Software's
         DB4</A
>. This is available since PHP 5.0.0.
        </TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="literal"
>cdb</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13;         Cdb is "a fast, reliable, lightweight package for creating and
         reading constant databases." It is from the author of qmail and
         can be found <A
HREF="http://cr.yp.to/cdb.html"
TARGET="_top"
>here</A
>. Since it is
         constant, we support only reading operations. And since PHP 4.3.0
         we support writing (not updating) through the internal cdb library.
        </TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="literal"
>cdb_make</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13;         Since PHP 4.3.0 we support creation (not updating) of cdb files 
         when the bundeled cdb library is used.
        </TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="literal"
>flatfile</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13;         This is available since PHP 4.3.0 for compatibility with the deprecated
         <A
HREF="ref.dbm.html"
>dbm</A
> extension only and should be avoided. 
         However you may use this where files were created in this format. That
         happens when configure could not find any external library.
        </TD
></TR
></TBODY
></TABLE
></DIV
>
    </P
><P
>&#13;     When invoking the <A
HREF="function.dba-open.html"
><B
CLASS="function"
>dba_open()</B
></A
> or
     <A
HREF="function.dba-popen.html"
><B
CLASS="function"
>dba_popen()</B
></A
> functions, one of the
     handler names must be supplied as an argument. The actually
     available list of handlers is displayed by invoking
     <A
HREF="function.phpinfo.html"
><B
CLASS="function"
>phpinfo()</B
></A
> or <A
HREF="function.dba-handlers.html"
><B
CLASS="function"
>dba_handlers()</B
></A
>.
    </P
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="dba.installation"
></A
>Installation</H1
><P
>&#13;  By using the <TT
CLASS="option"
>--enable-dba=shared</TT
>
  configuration option you can build a dynamic loadable modul to enable PHP
  for basic support of dbm-style databases. You also have to add support
  for at least one of the following handlers by specifying the
  <TT
CLASS="literal"
>--with-XXXX</TT
> configure switch to your PHP configure
  line.
  <DIV
CLASS="table"
><A
NAME="AEN15796"
></A
><P
><B
>Table 2. Supported DBA handlers</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Handler</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Configure Switch</TH
></TR
></THEAD
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="literal"
>dbm</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13;       To enable support for dbm add
       <TT
CLASS="option"
>--with-dbm[=DIR]</TT
>.
      </TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="literal"
>ndbm</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13;      To enable support for ndbm add
      <TT
CLASS="option"
>--with-ndbm[=DIR]</TT
>.
     </TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="literal"
>gdbm</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13;      To enable support for gdbm add
      <TT
CLASS="option"
>--with-gdbm[=DIR]</TT
>.
     </TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="literal"
>db2</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13;      To enable support for db2 add
      <TT
CLASS="option"
>--with-db2[=DIR]</TT
>.
      <DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Note: </B
>
        db2 conflicts with db3 and db4.
       </P
></BLOCKQUOTE
></DIV
>
     </TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="literal"
>db3</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13;      To enable support for db3 add
      <TT
CLASS="option"
>--with-db3[=DIR]</TT
>.
      <DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Note: </B
>
        db3 conflicts with db2 and db4.
       </P
></BLOCKQUOTE
></DIV
>
     </TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="literal"
>db4</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13;      To enable support for db4 add
      <TT
CLASS="option"
>--with-db4[=DIR]</TT
>.
      <DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Note: </B
>
        db4 conflicts with db2 and db3.
       </P
></BLOCKQUOTE
></DIV
>
      <DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Note: </B
>
        This was added in PHP 5.0.0. In earlier version you need to use
        <TT
CLASS="option"
>--with-db3=DIR</TT
> with DIR being the
        path to db4 librarie. It is not possible to use db versions starting 
        from 4.1 with PHP prior to version 4.3.0.
       </P
></BLOCKQUOTE
></DIV
>
     </TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="literal"
>cdb</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13;      To enable support for cdb add
      <TT
CLASS="option"
>--with-cdb[=DIR]</TT
>.
      <DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Note: </B
>
        Since PHP 4.3.0 you can omit DIR to use the bundeled cdb library 
        that adds the cdb_make handler which allows creation of cdb files
        and allows to access cdb files on the network using php's streams.
       </P
></BLOCKQUOTE
></DIV
>
     </TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="literal"
>flatfile</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13;      To enable support for flatfile add
      <TT
CLASS="option"
>--with-flatfile</TT
>.
      <DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Note: </B
>
        This was added in PHP 4.3.0 to add compatibility with deprecated
        <A
HREF="ref.dbm.html"
>dbm</A
> extension. Uee this handler only
        when you cannot install one of the libraries required by the other
        handlers and when you cannot use bundeled cdb handler.
       </P
></BLOCKQUOTE
></DIV
>
     </TD
></TR
></TBODY
></TABLE
></DIV
>
  <DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Note: </B
>
    Up to PHP 4.3.0 you are able to add both db2 and db3 handler but only one
    of them can be used internally. That means that you cannot have both file 
    formats. Starting with PHP 5.0.0 there is a configuration check avoid such
    missconfigurations.
   </P
></BLOCKQUOTE
></DIV
>
 </P
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="dba.runtime"
></A
>Runtime Configuration</H1
><P
>This extension has no configuration directives defined in <TT
CLASS="filename"
>php.ini</TT
>.</P
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="dba.resources"
></A
>Resource Types</H1
><P
>&#13;    The functions <A
HREF="function.dba-open.html"
><B
CLASS="function"
>dba_open()</B
></A
> and
    <A
HREF="function.dba-popen.html"
><B
CLASS="function"
>dba_popen()</B
></A
> return a handle to the specified
    database file to access which is used by all other dba-function calls.
    </P
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="dba.constants"
></A
>Predefined Constants</H1
><P
>This extension has no constants defined.</P
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="dba.examples"
></A
>Examples</H1
><P
>&#13;      <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN15875"
></A
><P
><B
>Example 1. DBA example</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>&#60;?php

$id = dba_open ("/tmp/test.db", "n", "db2");

if (!$id) {
    echo "dba_open failed\n";
    exit;
}

dba_replace ("key", "This is an example!", $id);

if (dba_exists ("key", $id)) {
    echo dba_fetch ("key", $id);
    dba_delete ("key", $id);
}

dba_close ($id);
?&#62;</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
    </P
><P
>&#13;     DBA is binary safe and does not have any arbitrary limits.
     However, it inherits all limits set by the underlying
     database implementation.
    </P
><P
>&#13;     All file-based databases must provide a way of setting the file
     mode of a new created database, if that is possible at all. The
     file mode is commonly passed as the fourth argument to
     <A
HREF="function.dba-open.html"
><B
CLASS="function"
>dba_open()</B
></A
> or <A
HREF="function.dba-popen.html"
><B
CLASS="function"
>dba_popen()</B
></A
>.
    </P
><P
>&#13;     You can access all entries of a database in a linear way by using the
     <A
HREF="function.dba-firstkey.html"
><B
CLASS="function"
>dba_firstkey()</B
></A
> and <A
HREF="function.dba-nextkey.html"
><B
CLASS="function"
>dba_nextkey()</B
></A
>
     functions. You may not change the database while traversing it.
    </P
><P
>&#13;     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN15886"
></A
><P
><B
>Example 2. Traversing a database</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>&#60;?php

// ...open database...

$key = dba_firstkey ($id);

while ($key != false) {
    if (...) {          // remember the key to perform some action later
        $handle_later[] = $key;
    }
    $key = dba_nextkey ($id);
}

for ($i = 0; $i &#60; count($handle_later); $i++)
    dba_delete ($handle_later[$i], $id);

?&#62;</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
    </P
></DIV
></DIV
><DIV
CLASS="TOC"
><DL
><DT
><B
>Table of Contents</B
></DT
><DT
><A
HREF="function.dba-close.html"
>dba_close</A
>&nbsp;--&nbsp;Close database</DT
><DT
><A
HREF="function.dba-delete.html"
>dba_delete</A
>&nbsp;--&nbsp;Delete entry specified by key</DT
><DT
><A
HREF="function.dba-exists.html"
>dba_exists</A
>&nbsp;--&nbsp;Check whether key exists</DT
><DT
><A
HREF="function.dba-fetch.html"
>dba_fetch</A
>&nbsp;--&nbsp;Fetch data specified by key</DT
><DT
><A
HREF="function.dba-firstkey.html"
>dba_firstkey</A
>&nbsp;--&nbsp;Fetch first key</DT
><DT
><A
HREF="function.dba-handlers.html"
>dba_handlers</A
>&nbsp;--&nbsp;List handlers available</DT
><DT
><A
HREF="function.dba-insert.html"
>dba_insert</A
>&nbsp;--&nbsp;Insert entry</DT
><DT
><A
HREF="function.dba-list.html"
>dba_list</A
>&nbsp;--&nbsp;List all open database files</DT
><DT
><A
HREF="function.dba-nextkey.html"
>dba_nextkey</A
>&nbsp;--&nbsp;Fetch next key</DT
><DT
><A
HREF="function.dba-open.html"
>dba_open</A
>&nbsp;--&nbsp;Open database</DT
><DT
><A
HREF="function.dba-optimize.html"
>dba_optimize</A
>&nbsp;--&nbsp;Optimize database</DT
><DT
><A
HREF="function.dba-popen.html"
>dba_popen</A
>&nbsp;--&nbsp;Open database persistently</DT
><DT
><A
HREF="function.dba-replace.html"
>dba_replace</A
>&nbsp;--&nbsp;Replace or insert entry</DT
><DT
><A
HREF="function.dba-sync.html"
>dba_sync</A
>&nbsp;--&nbsp;Synchronize database</DT
></DL
></DIV
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="function.ctype-xdigit.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.dba-close.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>ctype_xdigit</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="funcref.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>dba_close</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>