php - Yii transaction not rollbacked -
i 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
Post a Comment