1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
|
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="function.dba-open" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>dba_open</refname>
<refpurpose>Open database</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type class="union"><type>Dba\Connection</type><type>false</type></type><methodname>dba_open</methodname>
<methodparam><type>string</type><parameter>path</parameter></methodparam>
<methodparam><type>string</type><parameter>mode</parameter></methodparam>
<methodparam choice="opt"><type class="union"><type>string</type><type>null</type></type><parameter>handler</parameter><initializer>&null;</initializer></methodparam>
<methodparam choice="opt"><type>int</type><parameter>permission</parameter><initializer>0644</initializer></methodparam>
<methodparam choice="opt"><type>int</type><parameter>map_size</parameter><initializer>0</initializer></methodparam>
<methodparam choice="opt"><type class="union"><type>int</type><type>null</type></type><parameter>flags</parameter><initializer>&null;</initializer></methodparam>
</methodsynopsis>
<para>
<function>dba_open</function> establishes a database instance for
<parameter>path</parameter> with <parameter>mode</parameter> using
<parameter>handler</parameter>.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>path</parameter></term>
<listitem>
<para>
Commonly a regular path in your filesystem.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>mode</parameter></term>
<listitem>
<para>
It is <literal>r</literal> for read access, <literal>w</literal> for
read/write access to an already existing database, <literal>c</literal>
for read/write access and database creation if it doesn't currently exist,
and <literal>n</literal> for create, truncate and read/write access.
The database is created in BTree mode, other modes (like Hash or Queue)
are not supported.
</para>
<para>
Additionally you can set the database lock method with the next char.
Use <literal>l</literal> to lock the database with a <filename>.lck</filename>
file or <literal>d</literal> to lock the databasefile itself. It is
important that all of your applications do this consistently.
</para>
<para>
If you want to test the access and do not want to wait for the lock
you can add <literal>t</literal> as third character. When you are
absolutely sure that you do not require database locking you can do
so by using <literal>-</literal> instead of <literal>l</literal> or
<literal>d</literal>. When none of <literal>d</literal>,
<literal>l</literal> or <literal>-</literal> is used, dba will lock
on the database file as it would with <literal>d</literal>.
</para>
<note>
<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>
<title>DBA locking</title>
<tgroup cols="9">
<thead>
<row>
<entry>already open</entry>
<entry><parameter>mode</parameter> = "rl"</entry>
<entry><parameter>mode</parameter> = "rlt"</entry>
<entry><parameter>mode</parameter> = "wl"</entry>
<entry><parameter>mode</parameter> = "wlt"</entry>
<entry><parameter>mode</parameter> = "rd"</entry>
<entry><parameter>mode</parameter> = "rdt"</entry>
<entry><parameter>mode</parameter> = "wd"</entry>
<entry><parameter>mode</parameter> = "wdt"</entry>
</row>
</thead>
<tbody>
<row>
<entry>not open</entry>
<entry>ok</entry>
<entry>ok</entry>
<entry>ok</entry>
<entry>ok</entry>
<entry>ok</entry>
<entry>ok</entry>
<entry>ok</entry>
<entry>ok</entry>
</row>
<row>
<entry><parameter>mode</parameter> = "rl"</entry>
<entry>ok</entry>
<entry>ok</entry>
<entry>wait</entry>
<entry>false</entry>
<entry>illegal</entry>
<entry>illegal</entry>
<entry>illegal</entry>
<entry>illegal</entry>
</row>
<row>
<entry><parameter>mode</parameter> = "wl"</entry>
<entry>wait</entry>
<entry>false</entry>
<entry>wait</entry>
<entry>false</entry>
<entry>illegal</entry>
<entry>illegal</entry>
<entry>illegal</entry>
<entry>illegal</entry>
</row>
<row>
<entry><parameter>mode</parameter> = "rd"</entry>
<entry>illegal</entry>
<entry>illegal</entry>
<entry>illegal</entry>
<entry>illegal</entry>
<entry>ok</entry>
<entry>ok</entry>
<entry>wait</entry>
<entry>false</entry>
</row>
<row>
<entry><parameter>mode</parameter> = "wd"</entry>
<entry>illegal</entry>
<entry>illegal</entry>
<entry>illegal</entry>
<entry>illegal</entry>
<entry>wait</entry>
<entry>false</entry>
<entry>wait</entry>
<entry>false</entry>
</row>
</tbody>
</tgroup>
</table>
<simplelist>
<member>ok: the second call will be successful.</member>
<member>wait: the second call waits until <function>dba_close</function> is called for the first.</member>
<member>false: the second call returns false.</member>
<member>illegal: you must not mix <literal>"l"</literal> and <literal>"d"</literal> modifiers for <parameter>mode</parameter> parameter.</member>
</simplelist>
</para>
</note>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>handler</parameter></term>
<listitem>
<para>
The name of the <link linkend="dba.requirements">handler</link> which
shall be used for accessing <parameter>path</parameter>. It is passed
all optional parameters given to <function>dba_open</function> and
can act on behalf of them. If <parameter>handler</parameter> is &null;,
then the default handler is invoked.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>permission</parameter></term>
<listitem>
<para>
Optional &integer; parameter which is passed to the driver. It has the same meaning as
the <parameter>permissions</parameter> parameter of <function>chmod</function>,
and defaults to <literal>0644</literal>.
</para>
<para>
The <literal>db1</literal>, <literal>db2</literal>, <literal>db3</literal>,
<literal>db4</literal>, <literal>dbm</literal>, <literal>gdbm</literal>,
<literal>ndbm</literal>, and <literal>lmdb</literal> drivers support the
<parameter>permission</parameter> parameter.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>map_size</parameter></term>
<listitem>
<para>
Optional &integer; 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.
</para>
<para>
Only the <literal>lmdb</literal> driver accepts the <parameter>map_size</parameter> parameter.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>flags</parameter></term>
<listitem>
<para>
Flags to pass to the database drivers. If &null; the default flags will be provided.
Currently, only the LMDB driver supports the following flags
<constant>DBA_LMDB_USE_SUB_DIR</constant> and
<constant>DBA_LMDB_NO_SUB_DIR</constant>.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns a <classname>Dba\Connection</classname> instance on success&return.falseforfailure;.
</para>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<para>
&false; is returned and an <constant>E_WARNING</constant> level error is issued when
<parameter>handler</parameter> is &null;, but there is no default handler.
</para>
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>8.4.0</entry>
<entry>
Returns a <classname>Dba\Connection</classname> instance now;
previously, a &resource; was returned.
</entry>
</row>
<row>
<entry>8.2.0</entry>
<entry>
<parameter>flags</parameter> is added.
</entry>
</row>
<row>
<entry>8.2.0</entry>
<entry>
<parameter>handler</parameter> is now nullable.
</entry>
</row>
<row>
<entry>7.3.14, 7.4.2</entry>
<entry>
The <literal>lmdb</literal> driver now supports an additional <parameter>map_size</parameter>
parameter.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>dba_popen</function></member>
<member><function>dba_close</function></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- 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:"~/.phpdoc/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
-->
|