<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/dba.examples.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'dba.example.php',
    1 => 'Basic usage',
    2 => 'Basic usage',
  ),
  'up' => 
  array (
    0 => 'dba.examples.php',
    1 => 'Examples',
  ),
  'prev' => 
  array (
    0 => 'dba.examples.php',
    1 => 'Examples',
  ),
  'next' => 
  array (
    0 => 'class.dba-connection.php',
    1 => 'Dba\\Connection',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/dba/examples.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="dba.example" class="section">
  <h2 class="title">Basic usage</h2>
   <div class="example" id="example-1">
    <p><strong>Example #1 DBA example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br />$id </span><span style="color: #007700">= </span><span style="color: #0000BB">dba_open</span><span style="color: #007700">(</span><span style="color: #DD0000">"/tmp/test.db"</span><span style="color: #007700">, </span><span style="color: #DD0000">"n"</span><span style="color: #007700">, </span><span style="color: #DD0000">"db2"</span><span style="color: #007700">);<br /><br />if (!</span><span style="color: #0000BB">$id</span><span style="color: #007700">) {<br />    echo </span><span style="color: #DD0000">"dba_open failed\n"</span><span style="color: #007700">;<br />    exit;<br />}<br /><br /></span><span style="color: #0000BB">dba_replace</span><span style="color: #007700">(</span><span style="color: #DD0000">"key"</span><span style="color: #007700">, </span><span style="color: #DD0000">"This is an example!"</span><span style="color: #007700">, </span><span style="color: #0000BB">$id</span><span style="color: #007700">);<br /><br />if (</span><span style="color: #0000BB">dba_exists</span><span style="color: #007700">(</span><span style="color: #DD0000">"key"</span><span style="color: #007700">, </span><span style="color: #0000BB">$id</span><span style="color: #007700">)) {<br />    echo </span><span style="color: #0000BB">dba_fetch</span><span style="color: #007700">(</span><span style="color: #DD0000">"key"</span><span style="color: #007700">, </span><span style="color: #0000BB">$id</span><span style="color: #007700">);<br />    </span><span style="color: #0000BB">dba_delete</span><span style="color: #007700">(</span><span style="color: #DD0000">"key"</span><span style="color: #007700">, </span><span style="color: #0000BB">$id</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">dba_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$id</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

  </div>
  <p class="simpara">
   DBA is binary safe and does not have any arbitrary limits.
   However, it inherits all limits set by the underlying
   database implementation.
  </p>
  <p class="simpara">
   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
   <span class="function"><a href="function.dba-open.php" class="function">dba_open()</a></span> or <span class="function"><a href="function.dba-popen.php" class="function">dba_popen()</a></span>.
  </p>
  <p class="simpara">
   You can access all entries of a database in a linear way by using the
   <span class="function"><a href="function.dba-firstkey.php" class="function">dba_firstkey()</a></span> and <span class="function"><a href="function.dba-nextkey.php" class="function">dba_nextkey()</a></span>
   functions. You may not change the database while traversing it.
  </p>
  <div class="example" id="example-2">
   <p><strong>Example #2 Traversing a database</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">// ...open database...<br /><br /></span><span style="color: #0000BB">$key </span><span style="color: #007700">= </span><span style="color: #0000BB">dba_firstkey</span><span style="color: #007700">(</span><span style="color: #0000BB">$id</span><span style="color: #007700">);<br /><br />while (</span><span style="color: #0000BB">$key </span><span style="color: #007700">!== </span><span style="color: #0000BB">false</span><span style="color: #007700">) {<br />    if (</span><span style="color: #0000BB">true</span><span style="color: #007700">) {          </span><span style="color: #FF8000">// remember the key to perform some action later<br />        </span><span style="color: #0000BB">$handle_later</span><span style="color: #007700">[] = </span><span style="color: #0000BB">$key</span><span style="color: #007700">;<br />    }<br />    </span><span style="color: #0000BB">$key </span><span style="color: #007700">= </span><span style="color: #0000BB">dba_nextkey</span><span style="color: #007700">(</span><span style="color: #0000BB">$id</span><span style="color: #007700">);<br />}<br /><br />foreach (</span><span style="color: #0000BB">$handle_later </span><span style="color: #007700">as </span><span style="color: #0000BB">$val</span><span style="color: #007700">) {<br />    </span><span style="color: #0000BB">dba_delete</span><span style="color: #007700">(</span><span style="color: #0000BB">$val</span><span style="color: #007700">, </span><span style="color: #0000BB">$id</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

  </div>
 </div><?php manual_footer($setup); ?>