Yii Framework v1.1.10 绫诲弬鑰

CDbTransaction

system.db
缁ф壙 class CDbTransaction » CComponent
婧愯嚜 1.0
鐗堟湰 $Id: CDbTransaction.php 3426 2011-10-25 00:01:09Z alexander.makarow $
婧愮爜 framework/db/CDbTransaction.php
CDbTransaction琛ㄧず涓涓暟鎹簱浜嬪姟銆

瀹冮氬父閫氳繃璋冪敤CDbConnection::beginTransaction鍒涘缓銆

浠ヤ笅浠g爜鏄娇鐢ㄤ簨鍔$殑涓绉嶅父瑙佹儏褰細
$transaction=$connection->beginTransaction();
try
{
   $connection->createCommand($sql1)->execute();
   $connection->createCommand($sql2)->execute();
   //.... other SQL executions
   $transaction->commit();
}
catch(Exception $e)
{
   $transaction->rollBack();
}

鍏叡灞炴

闅愯棌缁ф壙灞炴

灞炴绫诲瀷鎻忚堪瀹氫箟鍦
active boolean 杩斿洖鏄惁杩欎釜浜嬪姟鏄縺娲荤姸鎬 CDbTransaction
connection CDbConnection 杩斿洖杩欎釜浜嬪姟鐨勬暟鎹簱杩炴帴 CDbTransaction

鍏叡鏂规硶

闅愯棌缁ф壙鏂规硶

鏂规硶鎻忚堪瀹氫箟鍦
__call() 濡傛灉绫讳腑娌℃湁璋冪殑鏂规硶鍚嶏紝鍒欒皟鐢ㄨ繖涓柟娉曘 CComponent
__construct() 鏋勯犲嚱鏁般 CDbTransaction
__get() 杩斿洖涓涓睘鎬у笺佷竴涓簨浠跺鐞嗙▼搴忓垪琛ㄦ垨涓涓涓哄悕绉般 CComponent
__isset() 妫鏌ヤ竴涓睘鎬ф槸鍚︿负null銆 CComponent
__set() 璁剧疆涓涓粍浠剁殑灞炴у笺 CComponent
__unset() 璁剧疆涓涓粍浠剁殑灞炴т负null銆 CComponent
asa() 杩斿洖杩欎釜鍚嶅瓧鐨勮涓哄璞° CComponent
attachBehavior() 闄勫姞涓涓涓哄埌缁勪欢銆 CComponent
attachBehaviors() 闄勫姞涓涓涓哄垪琛ㄥ埌缁勪欢銆 CComponent
attachEventHandler() 涓轰簨浠堕檮鍔犱竴涓簨浠跺鐞嗙▼搴忋 CComponent
canGetProperty() 纭畾灞炴ф槸鍚﹀彲璇汇 CComponent
canSetProperty() 纭畾灞炴ф槸鍚﹀彲鍐欍 CComponent
commit() 鎻愪氦涓涓簨鍔° CDbTransaction
detachBehavior() 浠庣粍浠朵腑鍒嗙涓涓涓恒 CComponent
detachBehaviors() 浠庣粍浠朵腑鍒嗙鎵鏈夎涓恒 CComponent
detachEventHandler() 鍒嗙涓涓瓨鍦ㄧ殑浜嬩欢澶勭悊绋嬪簭銆 CComponent
disableBehavior() 绂佺敤涓涓檮鍔犺涓恒 CComponent
disableBehaviors() 绂佺敤缁勪欢闄勫姞鐨勬墍鏈夎涓恒 CComponent
enableBehavior() 鍚敤涓涓檮鍔犺涓恒 CComponent
enableBehaviors() 鍚敤缁勪欢闄勫姞鐨勬墍鏈夎涓恒 CComponent
evaluateExpression() 璁$畻涓涓狿HP琛ㄨ揪寮忥紝鎴栨牴鎹粍浠朵笂涓嬫枃鎵ц鍥炶皟銆 CComponent
getActive() 杩斿洖杩斿洖鏄惁杩欎釜浜嬪姟鏄縺娲荤姸鎬 CDbTransaction
getConnection() 杩斿洖杩斿洖杩欎釜浜嬪姟鐨勬暟鎹簱杩炴帴 CDbTransaction
getEventHandlers() 杩斿洖涓涓簨浠剁殑闄勫姞澶勭悊绋嬪簭鍒楄〃銆 CComponent
hasEvent() 纭畾涓涓簨浠舵槸鍚﹀畾涔夈 CComponent
hasEventHandler() 妫鏌ヤ簨浠舵槸鍚︽湁闄勫姞鐨勫鐞嗙▼搴忋 CComponent
hasProperty() 纭畾灞炴ф槸鍚﹁瀹氫箟銆 CComponent
raiseEvent() 鍙戣捣涓涓簨浠躲 CComponent
rollback() 鍥炴粴涓涓簨鍔° CDbTransaction

鍙椾繚鎶ゆ柟娉

闅愯棌缁ф壙鏂规硶

鏂规硶鎻忚堪瀹氫箟鍦
setActive() 璁剧疆鏄惁杩欎釜浜嬪姟鏄縺娲荤姸鎬 CDbTransaction

灞炴ц缁

active 灞炴
public boolean getActive()
protected void setActive(boolean $value)

杩斿洖鏄惁杩欎釜浜嬪姟鏄縺娲荤姸鎬

connection 灞炴 鍙

杩斿洖杩欎釜浜嬪姟鐨勬暟鎹簱杩炴帴

鏂规硶璇︾粏

__construct() 鏂规硶
public void __construct(CDbConnection $connection)
$connection CDbConnection 鍏宠仈鍒拌浜嬪姟鐨勬暟鎹簱杩炴帴
婧愮爜锛 framework/db/CDbTransaction.php#50 (鏄剧ず)
public function __construct(CDbConnection $connection)
{
    
$this->_connection=$connection;
    
$this->_active=true;
}

鏋勯犲嚱鏁般

commit() 鏂规硶
public void commit()
婧愮爜锛 framework/db/CDbTransaction.php#60 (鏄剧ず)
public function commit()
{
    if(
$this->_active && $this->_connection->getActive())
    {
        
Yii::trace('Committing transaction','system.db.CDbTransaction');
        
$this->_connection->getPdoInstance()->commit();
        
$this->_active=false;
    }
    else
        throw new 
CDbException(Yii::t('yii','CDbTransaction is inactive and cannot perform commit or roll back operations.'));
}

鎻愪氦涓涓簨鍔°

getActive() 鏂规硶
public boolean getActive()
{return} boolean 杩斿洖鏄惁杩欎釜浜嬪姟鏄縺娲荤姸鎬
婧愮爜锛 framework/db/CDbTransaction.php#99 (鏄剧ず)
public function getActive()
{
    return 
$this->_active;
}

getConnection() 鏂规硶
public CDbConnection getConnection()
{return} CDbConnection 杩斿洖杩欎釜浜嬪姟鐨勬暟鎹簱杩炴帴
婧愮爜锛 framework/db/CDbTransaction.php#91 (鏄剧ず)
public function getConnection()
{
    return 
$this->_connection;
}

rollback() 鏂规硶
public void rollback()
婧愮爜锛 framework/db/CDbTransaction.php#76 (鏄剧ず)
public function rollback()
{
    if(
$this->_active && $this->_connection->getActive())
    {
        
Yii::trace('Rolling back transaction','system.db.CDbTransaction');
        
$this->_connection->getPdoInstance()->rollBack();
        
$this->_active=false;
    }
    else
        throw new 
CDbException(Yii::t('yii','CDbTransaction is inactive and cannot perform commit or roll back operations.'));
}

鍥炴粴涓涓簨鍔°

setActive() 鏂规硶
protected void setActive(boolean $value)
$value boolean 鏄惁杩欎釜浜嬪姟鏄縺娲荤姸鎬
婧愮爜锛 framework/db/CDbTransaction.php#107 (鏄剧ず)
protected function setActive($value)
{
    
$this->_active=$value;
}

Copyright © 2008-2011 by Yii Software LLC
All Rights Reserved.