⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 transactional_counter.php

📁 linux 下的源代码分析阅读器 red hat公司新版
💻 PHP
字号:
<?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();?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -