| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 | 
							- <?php
 
- namespace KIF\Db;
 
- use KIF\Exception\ParamsException;
 
- use KIF\Db\MySQLi;
 
- use KIF\Core\Config;
 
- /**
 
-  * 数据库事务类
 
-  * 主要是包装 MySQLite 的事务方法。供前端类、前端php响应页面调用。
 
-  * @author gaoxiaogang@gmail.com
 
-  *
 
-  */
 
- class Transaction {
 
-     /**
 
-      * 数据库实例
 
-      *
 
-      * @var KIF\Db\MySQLi
 
-      */
 
-     protected $db;
 
-     public function __construct($cluster_flag = 'default') {
 
-     	$appConfig = Config::getInstance()->current();
 
-     	$dbConfig = $appConfig['db'];
 
-     	
 
-     	if (!$dbConfig || !isset($dbConfig[$cluster_flag]) || !is_string($dbConfig[$cluster_flag])) {
 
-     		throw new ParamsException("load config error:{$dbConfig}");
 
-     	}
 
-    
 
-         $this->db = new MySQLi($dbConfig[$cluster_flag]);
 
-     }
 
-     /**
 
-      * 开始事务
 
-      * @return false | string false:失败;string:成功返回事务标志
 
-      */
 
-     public function start() {
 
-     	return $this->db->startTransaction();
 
-     }
 
-     /**
 
-      * 提交事务
 
-      * @param string $strTransactionId
 
-      * @return Boolean
 
-      */
 
-     public function commit($strTransactionId) {
 
-     	return $this->db->commit($strTransactionId);
 
-     }
 
-     /**
 
-      * 回滚事务
 
-      * @param string $strTransactionId
 
-      * @return Boolean
 
-      */
 
-     public function rollback($strTransactionId) {
 
-         return $this->db->rollback($strTransactionId);
 
-     }
 
-     /**
 
-      *
 
-      * 开始使用主库。后续的所有读查询,都会被强制到主库
 
-      *
 
-      * @return String 返回一串标志,供$this->restore 方法使用,用于恢复上一个状态
 
-      */
 
-     public function beginUseMaster() {
 
-     	return $this->db->beginUseMaster();
 
-     }
 
-     /**
 
-      * 恢复采用 $strMasterStatusId 为句柄保存的上次的状态
 
-      *
 
-      * @param String $strMasterStatusId
 
-      * @return Boolean
 
-      *
 
-      */
 
-     public function restore($strMasterStatusId) {
 
-     	return $this->db->restore($strMasterStatusId);
 
-     }
 
- }
 
 
  |