Example #1
0
<?php

// Open a new Db4Env
$dbenv = new Db4Env();
$dbenv->set_data_dir("/var/tmp/dbhome");
$dbenv->open("/var/tmp/dbhome");
// Open a database in $dbenv.  Note that even though
// we pass null in as the transaction, db4 forces this
// operation to be transactionally protected, so PHP
// will force auto-commit internally.
$db = new Db4($dbenv);
$db->open(null, 'a', 'foo');
$counter = $db->get("counter");
// Create a new transaction
$txn = $dbenv->txn_begin();
if ($txn == false) {
    print "txn_begin failed";
    exit;
}
print "Current value of counter is {$counter}\n";
// Increment and reset counter, protect it with $txn
$db->put("counter", $counter + 1, $txn);
// Commit the transaction, otherwise the above put() will rollback.
$txn->commit();
// Sync for good measure
$db->sync();
// This isn't a real close, use _close() for that.
$db->close();
Example #2
0
File: 10.php Project: kanbang/Colt
Create two XML Containers within a Berkeley DB environment,
then within a Berkeley DB transaction add a document to
each container.

EXPECTED RESULT:
Success
ACTUAL RESULT:
<?php 
$book_name = 'book1';
$book_content = '<book><title>Knowledge Discovery in Databases.</title></book>';
foreach (array_merge(glob("__db*"), glob("log.O"), glob("test*.dbxml")) as $file) {
    @unlink($file);
}
$env = new Db4Env();
$env->open();
$mgr = new XmlManager($env);
$config = new XmlContainerConfig();
$config->setTransactional(true);
$mgr->setDefaultContainerConfig($config);
$con1 = $mgr->createContainer("test.dbxml");
$con2 = $mgr->createContainer("test2.dbxml");
$txn = $mgr->createTransaction();
$con1->putDocument($txn, $book_name, $book_content);
$con2->putDocument($txn, $book_name, $book_content);
$txn->commit();
unset($con1);
unset($con2);
unset($mgr);
$env->close();
print "Success\n";
Example #3
0
<?php

// Open a new Db4Env.  By default it is transactional.  The directory
// path in the open() call must exist.
$dbenv = new Db4Env();
$dbenv->set_data_dir(".");
$dbenv->open(".");
// Open a database in $dbenv.
$db = new Db4($dbenv);
$txn = $dbenv->txn_begin();
$db->open($txn, 'a', 'foo');
$txn->commit();
$counter = $db->get("counter");
// Create a new transaction
$txn = $dbenv->txn_begin();
if ($txn == false) {
    print "txn_begin failed";
    exit;
}
print "Current value of counter is {$counter}\n";
// Increment and reset counter, protect it with $txn
$db->put("counter", $counter + 1, $txn);
// Commit the transaction, otherwise the above put() will rollback.
$txn->commit();
// Sync for good measure
$db->sync();
// This isn't a real close, use _close() for that.
$db->close();