1<?php 2 3// Open a new Db4Env 4$dbenv = new Db4Env(); 5$dbenv->set_data_dir("/var/tmp/dbhome"); 6$dbenv->open("/var/tmp/dbhome"); 7 8// Open a database in $dbenv. Note that even though 9// we pass null in as the transaction, db4 forces this 10// operation to be transactionally protected, so PHP 11// will force auto-commit internally. 12$db = new Db4($dbenv); 13$db->open(null, 'a', 'foo'); 14 15$counter = $db->get("counter"); 16// Create a new transaction 17$txn = $dbenv->txn_begin(); 18if($txn == false) { 19 print "txn_begin failed"; 20 exit; 21} 22print "Current value of counter is $counter\n"; 23 24// Increment and reset counter, protect it with $txn 25$db->put("counter", $counter+1, $txn); 26 27// Commit the transaction, otherwise the above put() will rollback. 28$txn->commit(); 29// Sync for good measure 30$db->sync(); 31// This isn't a real close, use _close() for that. 32$db->close(); 33?> 34