<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.dba.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'function.dba-open.php',
    1 => 'dba_open',
    2 => 'Open database',
  ),
  'up' => 
  array (
    0 => 'ref.dba.php',
    1 => 'DBA Funzioni',
  ),
  'prev' => 
  array (
    0 => 'function.dba-nextkey.php',
    1 => 'dba_nextkey',
  ),
  'next' => 
  array (
    0 => 'function.dba-optimize.php',
    1 => 'dba_optimize',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/dba/functions/dba-open.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.dba-open" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">dba_open</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">dba_open</span> &mdash; <span class="dc-title">Open database</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.dba-open-description">
  <h3 class="title">Descrizione</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>dba_open</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$path</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$mode</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$handler</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$permission</code><span class="initializer"> = 0644</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$map_size</code><span class="initializer"> = 0</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.integer.php" class="type int">int</a></span></span> <code class="parameter">$flags</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span><br>): <span class="type"><span class="type"><a href="class.dba-connection.php" class="type Dba\Connection">Dba\Connection</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="simpara">
   <span class="function"><strong>dba_open()</strong></span> establishes a database instance for
   <code class="parameter">path</code> with <code class="parameter">mode</code> using
   <code class="parameter">handler</code>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.dba-open-parameters">
  <h3 class="title">Elenco dei parametri</h3>
  <dl>
   
    <dt><code class="parameter">path</code></dt>
    <dd>
     <span class="simpara">
      Commonly a regular path in your filesystem.
     </span>
    </dd>
   
   
    <dt><code class="parameter">mode</code></dt>
    <dd>
     <span class="simpara">
      It is <code class="literal">r</code> for read access, <code class="literal">w</code> for
      read/write access to an already existing database, <code class="literal">c</code>
      for read/write access and database creation if it doesn&#039;t currently exist,
      and <code class="literal">n</code> for create, truncate and read/write access.
      The database is created in BTree mode, other modes (like Hash or Queue)
      are not supported.
     </span>
     <span class="simpara">
      Additionally you can set the database lock method with the next char.
      Use <code class="literal">l</code> to lock the database with a <var class="filename">.lck</var>
      file or <code class="literal">d</code> to lock the databasefile itself. It is
      important that all of your applications do this consistently.
     </span>
     <span class="simpara">
      If you want to test the access and do not want to wait for the lock
      you can add <code class="literal">t</code> as third character. When you are
      absolutely sure that you do not require database locking you can do
      so by using <code class="literal">-</code> instead of <code class="literal">l</code> or
      <code class="literal">d</code>. When none of <code class="literal">d</code>,
      <code class="literal">l</code> or <code class="literal">-</code> is used, dba will lock
      on the database file as it would with <code class="literal">d</code>.
     </span>
     <blockquote class="note"><p><strong class="note">Nota</strong>: 
      <p class="para">
       There can only be one writer for one database file. When you use dba on
       a web server and more than one request requires write operations they can
       only be done one after another. Also read during write is not allowed.
       The dba extension uses locks to prevent this. See the following table:
       <table class="doctable table">
        <caption><strong>DBA locking</strong></caption>
        
         <thead>
          <tr>
           <th>already open</th>
           <th><code class="parameter">mode</code> = &quot;rl&quot;</th>
           <th><code class="parameter">mode</code> = &quot;rlt&quot;</th>
           <th><code class="parameter">mode</code> = &quot;wl&quot;</th>
           <th><code class="parameter">mode</code> = &quot;wlt&quot;</th>
           <th><code class="parameter">mode</code> = &quot;rd&quot;</th>
           <th><code class="parameter">mode</code> = &quot;rdt&quot;</th>
           <th><code class="parameter">mode</code> = &quot;wd&quot;</th>
           <th><code class="parameter">mode</code> = &quot;wdt&quot;</th>
          </tr>

         </thead>

         <tbody class="tbody">
          <tr>
           <td>not open</td>
           <td>ok</td>
           <td>ok</td>
           <td>ok</td>
           <td>ok</td>
           <td>ok</td>
           <td>ok</td>
           <td>ok</td>
           <td>ok</td>
          </tr>

          <tr>
           <td><code class="parameter">mode</code> = &quot;rl&quot;</td>
           <td>ok</td>
           <td>ok</td>
           <td>wait</td>
           <td>false</td>
           <td>illegal</td>
           <td>illegal</td>
           <td>illegal</td>
           <td>illegal</td>
          </tr>

          <tr>
           <td><code class="parameter">mode</code> = &quot;wl&quot;</td>
           <td>wait</td>
           <td>false</td>
           <td>wait</td>
           <td>false</td>
           <td>illegal</td>
           <td>illegal</td>
           <td>illegal</td>
           <td>illegal</td>
          </tr>

          <tr>
           <td><code class="parameter">mode</code> = &quot;rd&quot;</td>
           <td>illegal</td>
           <td>illegal</td>
           <td>illegal</td>
           <td>illegal</td>
           <td>ok</td>
           <td>ok</td>
           <td>wait</td>
           <td>false</td>
          </tr>

          <tr>
           <td><code class="parameter">mode</code> = &quot;wd&quot;</td>
           <td>illegal</td>
           <td>illegal</td>
           <td>illegal</td>
           <td>illegal</td>
           <td>wait</td>
           <td>false</td>
           <td>wait</td>
           <td>false</td>
          </tr>

         </tbody>
        
       </table>

       <ul class="simplelist">
        <li>ok: the second call will be successful.</li>
        <li>wait: the second call waits until <span class="function"><a href="function.dba-close.php" class="function">dba_close()</a></span> is called for the first.</li>
        <li>false: the second call returns false.</li>
        <li>illegal: you must not mix <code class="literal">&quot;l&quot;</code> and <code class="literal">&quot;d&quot;</code> modifiers for <code class="parameter">mode</code> parameter.</li>
       </ul>
      </p>
     </p></blockquote>
    </dd>
   
   
    <dt><code class="parameter">handler</code></dt>
    <dd>
     <span class="simpara">
      The name of the <a href="dba.requirements.php" class="link">handler</a> which
      shall be used for accessing <code class="parameter">path</code>. It is passed
      all optional parameters given to <span class="function"><strong>dba_open()</strong></span> and
      can act on behalf of them. If <code class="parameter">handler</code> is <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>,
      then the default handler is invoked.
     </span>
    </dd>
   
   
    <dt><code class="parameter">permission</code></dt>
    <dd>
     <span class="simpara">
      Optional <span class="type"><a href="language.types.integer.php" class="type int">int</a></span> parameter which is passed to the driver. It has the same meaning as
      the <code class="parameter">permissions</code> parameter of <span class="function"><a href="function.chmod.php" class="function">chmod()</a></span>,
      and defaults to <code class="literal">0644</code>.
     </span>
     <span class="simpara">
      The <code class="literal">db1</code>, <code class="literal">db2</code>, <code class="literal">db3</code>,
      <code class="literal">db4</code>, <code class="literal">dbm</code>, <code class="literal">gdbm</code>,
      <code class="literal">ndbm</code>, and <code class="literal">lmdb</code> drivers support the
      <code class="parameter">permission</code> parameter.
     </span>
    </dd>
   
   
    <dt><code class="parameter">map_size</code></dt>
    <dd>
     <span class="simpara">
      Optional <span class="type"><a href="language.types.integer.php" class="type int">int</a></span> parameter which is passed to the driver. Its value should be a multiple of the
      page size of the OS, or zero, to use the default map size.
     </span>
     <span class="simpara">
      Only the <code class="literal">lmdb</code> driver accepts the <code class="parameter">map_size</code> parameter.
     </span>
    </dd>
   
   
    <dt><code class="parameter">flags</code></dt>
    <dd>
     <span class="simpara">
      Flags to pass to the database drivers. If <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> the default flags will be provided.
      Currently, only the LMDB driver supports the following flags
      <strong><code><a href="dba.constants.php#constant.dba-lmdb-use-sub-dir">DBA_LMDB_USE_SUB_DIR</a></code></strong> and
      <strong><code><a href="dba.constants.php#constant.dba-lmdb-no-sub-dir">DBA_LMDB_NO_SUB_DIR</a></code></strong>.
     </span>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.dba-open-returnvalues">
  <h3 class="title">Valori restituiti</h3>
  <p class="simpara">
   Returns a <span class="classname"><a href="class.dba-connection.php" class="classname">Dba\Connection</a></span> instance on success o <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> in caso di fallimento.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.dba-open-errors">
  <h3 class="title">Errori/Eccezioni</h3>
  <p class="simpara">
   <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> is returned and an <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> level error is issued when
   <code class="parameter">handler</code> is <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>, but there is no default handler.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.dba-open-changelog">
  <h3 class="title">Log delle modifiche</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Versione</th>
      <th>Descrizione</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.4.0</td>
      <td>
       Returns a <span class="classname"><a href="class.dba-connection.php" class="classname">Dba\Connection</a></span> instance now;
       previously, a <a href="language.types.resource.php" class="link">resource</a> was returned.
      </td>
     </tr>

     <tr>
      <td>8.2.0</td>
      <td>
       <code class="parameter">flags</code> is added.
      </td>
     </tr>

     <tr>
      <td>8.2.0</td>
      <td>
       <code class="parameter">handler</code> is now nullable.
      </td>
     </tr>

     <tr>
      <td>7.3.14, 7.4.2</td>
      <td>
       The <code class="literal">lmdb</code> driver now supports an additional <code class="parameter">map_size</code>
       parameter.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 seealso" id="refsect1-function.dba-open-seealso">
  <h3 class="title">Vedere anche:</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.dba-popen.php" class="function" rel="rdfs-seeAlso">dba_popen()</a> - Open database persistently</span></li>
   <li><span class="function"><a href="function.dba-close.php" class="function" rel="rdfs-seeAlso">dba_close()</a> - Close a DBA database</span></li>
  </ul>
 </div>

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