YII 事物无效问题 HELP HELP HELP HELP HELP HELP !!!!!!
各位大神们 入门PHP程序员求帮助
Yii事物
官方写法:
<br /> $transaction=$connection->beginTransaction();<br /> try<br /> {<br /> $connection->createCommand($sql1)->execute();<br /> $connection->createCommand($sql2)->execute();<br /> //.... other SQL executions<br /> $transaction->commit();<br /> }<br /> catch(Exception $e)<br /> {<br /> $transaction->rollBack();<br /> }<br />
<br /> public function addCourseRecommend($courseRecommend,$payWayArray)<br /> {<br /> try{<br /> $connection=$this->getDb();<br /> $transaction=$connection->beginTransaction();<br /> $this->courseRecommendDb= new CourseRecommendDb($connection);<br /> $this->payWayDb=new PayWayDb($connection);<br /> $this->courseRecommendDb->addCourseRecommend($courseRecommend);<br /> foreach($payWayArray as $tempPayWay)<br /> {<br /> $this->payWayDb->addPayWay($tempPayWay);<br /> $tempPayWayRecommend =new PayWayRecommend();<br /> $this->payWayDb->addPayWayRecommend($tempPayWayRecommend);<br /> }<br /> $this->commit($transaction);<br /> }catch (Exception $e){<br /> $this->rollback($transaction);<br /> $this->closeLink();<br /> throw $e;<br /> }<br /> $this->closeLink();<br /> }<br /><br />