PHP Berkeley DB
Simple Berkeley DB wrapper for PHP., (*1)
Installation
Download Berkeley DB source:, (*2)
wget 'http://download.oracle.com/berkeley-db/db-x.x.x.tar.gz'
tar -xzvf db-x.x.x.tar.gz
Build Berkeley DB libraries and headers:, (*3)
cd db-x.x.x/build_unix/
../dist/configure --enable-cxx
make
make install
Install php_db4 extension for "phpdb4" adapter (better):, (*4)
Build db4 extension:, (*5)
cd ../lang/php4_db
phpize
./configure --with-db4=/usr/local/BerkeleyDB.x.x
make
make install
Add db4 extension to php.ini:, (*6)
extension=db4.so
Or install db4 DBA handler for "dba" adapter:, (*7)
Build PHP with db4 support:, (*8)
./configure --with-db4=/usr/local/BerkeleyDB.x.x
make
sudo make install
Install composer package:, (*9)
composer install andkom/php-berkeley-db
Usage
Create instance:, (*10)
use AndKom\BerkeleyDb\Adapter\AdapterFactory;
$adapter = AdapterFactory::create(); // use first available adapter
$adapter = AdapterFactory::create("phpdb4"); // use phpdb4 adapter
$adapter = AdapterFactory::create("dba"); // use dba adapter
Open database for reading:, (*11)
$adapter->open("filename", "r");
Open database with optional database name:, (*12)
$adapter->open("filename", "r", "main");
Open database for writing:, (*13)
$adapter->open("filename", "w");
Close database:, (*14)
$adapter->close();
Sync changes to database:, (*15)
$adapter->sync();
Read key value:, (*16)
$value = $adapter->get("key");
Write key value:, (*17)
$adapter->put("key", "value");
Delete key:, (*18)
$adapter->delete("key");
Returns first key and moves cursor to the next position:, (*19)
$adapter->firstKey();
Read next key and moves cursor to the next position:, (*20)
$adapter->nextKey();
Read all database keys:, (*21)
foreach ($adapter->read() as $key => $value) {
...
}
Laravel Service Provider
Publish configuration to app config:, (*22)
./artisan vendor:publish --provider=AndKom\\BerkeleyDb\\ServiceProvider
Edit app/config/berkeleydb.php:, (*23)
<?php
return [
'adapter' => 'phpdb4',
'filename' => database_path('database.dat'),
'database' => null,
'mode' => 'w',
];
Use BDB facade to access database methods:, (*24)
$value = BDB::get("key");