<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >dba_open</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="Manual do PHP" HREF="index.html"><LINK REL="UP" TITLE="Database (dbm-style) Abstraction Layer Functions" HREF="ref.dba.html"><LINK REL="PREVIOUS" TITLE="dba_nextkey" HREF="function.dba-nextkey.html"><LINK REL="NEXT" TITLE="dba_optimize" HREF="function.dba-optimize.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></HEAD ><BODY CLASS="refentry" 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" >Manual do PHP</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.dba-nextkey.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.dba-optimize.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.dba-open" ></A >dba_open</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN30513" ></A ><P > (PHP 3 >= 3.0.8, PHP 4, PHP 5)</P >dba_open -- Open database</DIV ><DIV CLASS="refsect1" ><A NAME="AEN30516" ></A ><H2 >Descrição</H2 >resource <B CLASS="methodname" >dba_open</B > ( string path, string mode [, string handler [, mixed ...]] )<BR ></BR ><P > <B CLASS="function" >dba_open()</B > 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" ><A NAME="AEN30538" ></A ><H2 >Parâmetros</H2 ><P > <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><CODE CLASS="parameter" >path</CODE ></DT ><DD ><P > Commonly a regular path in your filesystem. </P ></DD ><DT ><CODE CLASS="parameter" >mode</CODE ></DT ><DD ><P > It is <TT CLASS="literal" >r</TT > for read access, <TT CLASS="literal" >w</TT > for read/write access to an already existing database, <TT CLASS="literal" >c</TT > for read/write access and database creation if it doesn't currently exist, and <TT CLASS="literal" >n</TT > for create, truncate and read/write access. </P ><P > Additionally you can set the database lock method with the next char. Use <TT CLASS="literal" >l</TT > to lock the database with a <TT CLASS="filename" >.lck</TT > file or <TT CLASS="literal" >d</TT > to lock the databasefile itself. It is important that all of your applications do this consistently. </P ><P > If you want to test the access and do not want to wait for the lock you can add <TT CLASS="literal" >t</TT > as third character. When you are absolutely sure that you do not require database locking you can do so by using <TT CLASS="literal" >-</TT > instead of <TT CLASS="literal" >l</TT > or <TT CLASS="literal" >d</TT >. When none of <TT CLASS="literal" >d</TT >, <TT CLASS="literal" >l</TT > or <TT CLASS="literal" >-</TT > is used, dba will lock on the database file as it would with <TT CLASS="literal" >d</TT >. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Nota: </B > 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: <DIV CLASS="table" ><A NAME="AEN30571" ></A ><P ><B >Tabela 1. DBA locking</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><COL><COL><COL><COL><COL><COL><COL><COL><COL><THEAD ><TR ><TH >already open</TH ><TH ><CODE CLASS="parameter" >mode</CODE > = "rl"</TH ><TH ><CODE CLASS="parameter" >mode</CODE > = "rlt"</TH ><TH ><CODE CLASS="parameter" >mode</CODE > = "wl"</TH ><TH ><CODE CLASS="parameter" >mode</CODE > = "wlt"</TH ><TH ><CODE CLASS="parameter" >mode</CODE > = "rd"</TH ><TH ><CODE CLASS="parameter" >mode</CODE > = "rdt"</TH ><TH ><CODE CLASS="parameter" >mode</CODE > = "wd"</TH ><TH ><CODE CLASS="parameter" >mode</CODE > = "wdt"</TH ></TR ></THEAD ><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 > = "rl"</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 > = "wl"</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 > = "rd"</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 > = "wd"</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 ></DIV > <P ></P ><TABLE BORDER="0" ><TBODY ><TR ><TD >ok: the second call will be successfull.</TD ></TR ><TR ><TD >wait: the second call waits until <A HREF="function.dba-close.html" ><B CLASS="function" >dba_close()</B ></A > is called for the first.</TD ></TR ><TR ><TD >false: the second call returns false.</TD ></TR ><TR ><TD >illegal: you must not mix "l" and "d" modifiers for <CODE CLASS="parameter" >mode</CODE > parameter.</TD ></TR ></TBODY ></TABLE ><P ></P > </P ></BLOCKQUOTE ></DIV ></DD ><DT ><CODE CLASS="parameter" >handler</CODE ></DT ><DD ><P > The name of the <A HREF="ref.dba.html#dba.requirements" >handler</A > which shall be used for accessing <CODE CLASS="parameter" >path</CODE >. It is passed all optional parameters given to <B CLASS="function" >dba_open()</B > and can act on behalf of them. </P ></DD ></DL ></DIV > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN30663" ></A ><H2 >Valores de retornado</H2 ><P > Returns a positive handle on success, or <TT CLASS="constant" ><B >FALSE</B ></TT > on failure. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN30667" ></A ><H2 >Histórico</H2 ><P > <DIV CLASS="informaltable" ><P ></P ><A NAME="AEN30670" ></A ><TABLE BORDER="1" CLASS="CALSTABLE" ><COL><COL><THEAD ><TR ><TH >Versão</TH ><TH >Descrição</TH ></TR ></THEAD ><TBODY ><TR ><TD >4.3.0</TD ><TD > It's possible to open database files over network connection. However in cases a socket connection will be used (as with http or ftp) the connection will be locked instead of the resource itself. This is important to know since in such cases locking is simply ignored on the resource and other solutions have to be found. </TD ></TR ><TR ><TD >4.3.0</TD ><TD > Locking and the <CODE CLASS="parameter" >mode</CODE > modifiers "l", "d", "-" and "t" were added. In previous PHP versions, you must use semaphores to guard against simultaneous database access for any database handler with the exception of GDBM. See <A HREF="ref.sem.html" >System V semaphore support</A >. </TD ></TR ><TR ><TD >before 4.3.5</TD ><TD > open mode 'c' is broken for several internal handlers and truncates the database instead of appending data to an existent database. Also dbm and ndbm fail on mode 'c' in typical configurations (this cannot be fixed). </TD ></TR ></TBODY ></TABLE ><P ></P ></DIV > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN30688" ></A ><H2 >Veja também</H2 ><P > <P ></P ><TABLE BORDER="0" ><TBODY ><TR ><TD ><A HREF="function.dba-popen.html" ><B CLASS="function" >dba_popen()</B ></A ></TD ></TR ><TR ><TD ><A HREF="function.dba-close.html" ><B CLASS="function" >dba_close()</B ></A ></TD ></TR ></TBODY ></TABLE ><P ></P > </P ></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.dba-nextkey.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Principal</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.dba-optimize.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >dba_nextkey</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.dba.html" ACCESSKEY="U" >Acima</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >dba_optimize</TD ></TR ></TABLE ></DIV ></BODY ></HTML >