yii 进行事务操作是不可以在一条sql里边放多条sql

             $sql = 'INSERT INTO `table1`(`customerID`, `advertisementID`, `consumedStatus`, `consumedTime`) VALUES (:customerID,:advertisementID,:consumedStatus,:consumedTime);
                     UPDATE `table2` SET `consumedTimes`= `consumedTimes` + 1 WHERE `advertisementID`= :advertisementID;
                     UPDATE `table3` SET `appAdPoint`=`appAdPoint` + :price WHERE `customerID` = :customerID';
        
             $command = $connection->createCommand($sql);
             $command->bindParam(':customerID', $customerID);
             $command->bindParam(':advertisementID', $advertisementID);
             $command->bindParam(':consumedStatus', $consumedStatus);
             $command->bindParam(':consumedTime', date('Y-m-d H:i:s'));
             $command->bindParam(':price', $price);
             $updateStatus = $command->execute();
             $command->execute();

 注意:

  1. yii在进行如上的操作的时候,因为$sql中有三条sql语句导致了$command->execute();无法正常工作,这里它只检测第一条sql是否正常执行,后两条及时错了也无法通过$updateStatus显示出来!
  2. 一条sql中执行多条语句,无法进行事务transaction会导致无法更新数据库
原文地址:https://www.cnblogs.com/wlemory/p/4678933.html