1<!--$Id: php.so,v 10.3 2004/10/18 17:08:43 bostic Exp $--> 2<!--Copyright (c) 1997,2008 Oracle. All rights reserved.--> 3<!--See the file LICENSE for redistribution information.--> 4<html> 5<head> 6<title>Berkeley DB Reference Guide: Using Berkeley DB with PHP</title> 7<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit."> 8<meta name="keywords" content="embedded,database,programmatic,toolkit,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++"> 9</head> 10<body bgcolor=white> 11<a name="2"><!--meow--></a> 12<table width="100%"><tr valign=top> 13<td><b><dl><dt>Berkeley DB Reference Guide:<dd>Berkeley DB Extensions</dl></b></td> 14<td align=right><a href="/ext/perl.html"><img src="/images/prev.gif" alt="Prev"></a><a href="/toc.html"><img src="/images/ref.gif" alt="Ref"></a><a href="/dumpload/utility.html"><img src="/images/next.gif" alt="Next"></a> 15</td></tr></table> 16<p align=center><b>Using Berkeley DB with PHP</b></p> 17<p>A PHP 4 extension for this release of Berkeley DB is included in the 18distribution package. It can either either link directly against the 19installed Berkeley DB library (which is necessary for running in a 20non-Apache/mod_php4 environment), or against mod_db4, which provides 21additional safety when running under Apache/mod_php4.</p> 22<p>The PHP extension provides the following classes, which mirror the 23standard Berkeley DB C++ API.</p> 24<blockquote><pre>class Db4Env { 25<blockquote><pre>function Db4Env($flags = 0) {} 26function close($flags = 0) {} 27function dbremove($txn, $filename, $database = null, $flags = 0) {} 28function dbrename($txn, $file, $database, $new_database, $flags = 0) {} 29function open($home, $flags = DB_CREATE | DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_TXN, $mode = 0666) {} 30function remove($home, $flags = 0) {} 31function set_data_dir($directory) {} 32function txn_begin($parent_txn = null, $flags = 0) {} 33function txn_checkpoint($kbytes, $minutes, $flags = 0) {}</pre></blockquote> 34} 35<p> 36class Db4 { 37<blockquote><pre>function Db4($dbenv = null) {} // create a new Db4 object using the optional DbEnv 38function open($txn = null, $file = null, $database = null, $flags = DB_CREATE, $mode = 0) {} 39function close() {} 40function del($key, $txn = null) {} 41function get($key, $txn = null, $flags = 0) {} 42function pget($key, &$pkey, $txn = null, $flags = 0) {} 43function get_type() {} // returns the stringified database type name 44function stat($txn = null, $flags = 0) {} // returns statistics as an as 45function join($cursor_list, $flags = 0) {} 46function sync() {} 47function truncate($txn = null, $flags = 0) {} 48function cursor($txn = null, flags = 0) {}</pre></blockquote> 49} 50<p> 51class Db4Txn { 52<blockquote><pre>function abort() {} 53function commit() {} 54function discard() { 55function id() {} 56function set_timeout($timeout, $flags = 0) {}</pre></blockquote> 57} 58<p> 59class Db4Cursor { 60<blockquote><pre>function close() {} 61function count() {} 62function del() {} 63function dup($flags = 0) {} 64function get($key, $flags = 0) {} 65function pget($key, &$primary_key, $flags = 0) {} 66function put($key, $data, $flags = 0) {}</pre></blockquote> 67}</pre></blockquote> 68<p>The PHP extension attempts to be "smart" for you by:</p> 69<ol> 70<p><li>Auto-committing operations on transactional databases if no explicit 71Db4Txn object is specified. 72<p><li>Performing reference and dependency checking to insure that all 73resources are closed in the correct order. 74<p><li>Supplying default values for flags. 75</ol> 76<p>To install this PHP module linked against the mod_db4 framework, perform 77the following steps:</p> 78<blockquote><pre>% phpize 79% /configure --with-db4=[Berkeley DB library installation directory] \ 80 --with-mod_db4=$APACHE_INCLUDEDIR 81% make 82% make install</pre></blockquote> 83<p>Then, in your php.ini file add the following:</p> 84<blockquote><pre>extension=db4.so</pre></blockquote> 85<p>This extension will now only run in a SAPI linked into Apache httpd 86(mod_php4, most likely), and will take advantage of all of its 87auto-recovery and handle-caching facilities.</p> 88<p>To install this php module linked against the Berkeley DB library and not the 89mod_db4 framework, perform the following steps:</p> 90<blockquote><pre>% phpize 91% /configure --with-db4=[Berkeley DB library installation directory] 92% make 93% make install</pre></blockquote> 94<p>Then in your php.ini file add:</p> 95<blockquote><pre>extension=db4.so</pre></blockquote> 96<table width="100%"><tr><td><br></td><td align=right><a href="/ext/perl.html"><img src="/images/prev.gif" alt="Prev"></a><a href="/toc.html"><img src="/images/ref.gif" alt="Ref"></a><a href="/dumpload/utility.html"><img src="/images/next.gif" alt="Next"></a> 97</td></tr></table> 98<p><font size=1>Copyright (c) 1996,2008 Oracle. All rights reserved.</font> 99</body> 100</html> 101