php - Yii transaction not rollbacked -


enter image description herei have following piece of code , pass data generate exception , test if transaction rollback happening. seems it's not , i'm not sure why. can me? thanks

            $transaction = yii::app()->db->begintransaction();              try {                  //.....                  //call private methods                 $category = mycontroller::savecategory($params);                 $test_saved = mycontroller::savetest($params);                 mycontroller::savecommunity($param);   // here exception , should rollback transaction doesn't                    $transaction->commit();              } catch(exception $e) {                 $transaction->rollback();                 throw new exception($e);             }               private function savecommunity($param){                    $community = new community();                   $community->user_id = $user_id;                   $community->name = $name;                    $community->id = 71;  // duplicate primary key , generate exception                     try{                       $community->save(false, null);                   }catch(exception $e){                      throw $e;                   }                    return $community;              } 

(mysql tables set innodb)

try changing code responsible exception throwing:

          try{               $community->save(false, null);           }catch(exception $e){              throw $e;           } 

to like:

          if(!$community->save(false, null))                throw new exception('error saving'); 

and remove exception throwing here:

            } catch(exception $e) {             $transaction->rollback();             //throw new exception($e);         } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -