时间:2021-07-01 10:21:17 帮助过:15人阅读
$transaction=$connection->beginTransaction();
try
{
$connection->createCommand($sql1)->execute();
$connection->createCommand($sql2)->execute();
//.... other SQL executions
$transaction->commit();
}
catch(Exception $e)
{
$transaction->rollBack();
}
public function addCourseRecommend($courseRecommend,$payWayArray)
{
try{
$connection=$this->getDb();
$transaction=$connection->beginTransaction();
$this->courseRecommendDb= new CourseRecommendDb($connection);
$this->payWayDb=new PayWayDb($connection);
$this->courseRecommendDb->addCourseRecommend($courseRecommend);
foreach($payWayArray as $tempPayWay)
{
$this->payWayDb->addPayWay($tempPayWay);
$tempPayWayRecommend =new PayWayRecommend();
$this->payWayDb->addPayWayRecommend($tempPayWayRecommend);
}
$this->commit($transaction);
}catch (Exception $e){
$this->rollback($transaction);
$this->closeLink();
throw $e;
}
$this->closeLink();
}