transactiondemarcation Yii db transaction helper. Ensures your transactions.

  1. Requirements
  2. Usage

This helper class ensures a transaction to occure without error. Put your code within a transaction without worrying where the transaction started. If method mA() of Class A start a transaction and another method mB() of Class B also starts a transaction and call the mA() method, an error will occur transaction already started. With this helper you don't have to worry about this.

Requirements

Yii 1.1

Usage

Let say thers is

Class A
{
  public function mA()
  {
    Yii::app()->db->beginTransaction();
    ..
    ..
    Yii::app()->db->currentTransaction->commit();
  }
}

AND

Class B
{
  public function mB()
  {
    $a=new A();
    Yii::app()->db->beginTransaction();
    ..
    ..
    $a->mA(); //error occured
    ..
    ..
    Yii::app()->db->currentTransaction->commit();
  }
}

with TransactionHelper write the above code like below :

Class A
{
  public function mA()
  {
    $trans_key=TransactionHelper::beginTransaction();
    ..
    ..
    TransactionHelper::commit($trans_key);
  }
}

Class B
{
  public function mB()
  {
    $a=new A();
    $trans_key=TransactionHelper::beginTransaction();
    ..
    ..
    $a->mA(); //no error , transaction will not commit here
    ..
    ..
    TransactionHelper::commit($trans_key);
  }
}

Just put the TransactionHelper.php anywhere in your code.load it. Use it.

0 0
1 follower
106 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: Database
Developed by: Chandrakanta
Created on: May 5, 2014
Last updated: 10 years ago

Downloads

show all

Related Extensions