PHP: dba_open - Manual

downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

dba_optimize dba_nextkey

Last updated: Fri, 26 Jan 2007

view this page in

# dba_open

(PHP 3 >= 3.0.8, PHP 4, PHP 5)

dba_open -- Open database

## Описание

resource dba_open ( string path, string mode [, string handler [, mixed ...]] )

dba_open() establishes a database instance for `path` with `mode` using `handler`.

## Список параметров

`path`

  Commonly a regular path in your filesystem.

`mode`

  It is `r` for read access, `w` for read/write access to an already existing database, `c` for read/write access and database creation if it doesn't currently exist, and `n` for create, truncate and read/write access.

  Additionally you can set the database lock method with the next char. Use `l` to lock the database with a `.lck` file or `d` to lock the databasefile itself. It is important that all of your applications do this consistently.

  If you want to test the access and do not want to wait for the lock you can add `t` as third character. When you are absolutely sure that you do not require database locking you can do so by using `-` instead of `l` or `d`. When none of `d`, `l` or `-` is used, dba will lock on the database file as it would with `d`.

  > Замечание: There can only be one writer for one database file. When you use dba on a webserver 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:

  > Таблица 1. DBA locking

  > already open | `mode` = "rl" | `mode` = "rlt" | `mode` = "wl" | `mode` = "wlt" | `mode` = "rd" | `mode` = "rdt" | `mode` = "wd" | `mode` = "wdt"
  > --- | --- | --- | --- | --- | --- | --- | --- | ---
  > not open | ok | ok | ok | ok | ok | ok | ok | ok
  > `mode` = "rl" | ok | ok | wait | false | illegal | illegal | illegal | illegal
  > `mode` = "wl" | wait | false | wait | false | illegal | illegal | illegal | illegal
  > `mode` = "rd" | illegal | illegal | illegal | illegal | ok | ok | wait | false
  > `mode` = "wd" | illegal | illegal | illegal | illegal | wait | false | wait | false

  > ok: the second call will be successfull.
  > wait: the second call waits until dba_close() is called for the first.
  > false: the second call returns false.
  > illegal: you must not mix "l" and "d" modifiers for `mode` parameter.

`handler`

  The name of the handler which shall be used for accessing `path`. It is passed all optional parameters given to dba_open() and can act on behalf of them.

## Возвращаемые значения

Returns a positive handle on success, or `FALSE` on failure.

## Список изменений

Версия | Описание
--- | ---
4.3.0 | 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.
4.3.0 | Locking and the `mode` 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 System V semaphore support.
before 4.3.5 | 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).

## Смотрите также

dba_popen()
dba_close()

add a note User Contributed Notes
dba_open
doppelbauer at gmail dot com
20-Oct-2006 07:36
`Windows does not support locking the database. You may use $_ENV to determine the OS:
$locking = (stripos($_ENV['OS'],'windows') === false ? 'd' : 'l');`
xy ät affenkrieger.de
30-Mar-2006 06:13
`If you get some strange errors like
dba_open(): myDbFilename.db : Permission denied
than you are propably using PHP on a Windoze machine. You have to make sure that the following conditions are met:
1) Use an absolute path to your db file. Relative paths will cause problems with locking
2) Specify a locking mode - that's the second character of the mode-argument, or else opening a dba-file will cause several notices/warnings etc.
And a final, general note:
3) Always use the english PHP doc on this site - the translations are often old as hell and miss important informations
HTH, Nils.`
add a note
dba_optimize dba_nextkey

Last updated: Fri, 26 Jan 2007
show source | credits | stats | sitemap | contact | advertising | mirror sites
Copyright © 2001-2007 The PHP Group
All rights reserved.
This mirror generously provided by: Yahoo! Inc.
Last updated: Sat Mar 10 09:32:46 2007 PST