zoukankan      html  css  js  c++  java
  • 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会导致无法更新数据库
  • 相关阅读:
    cf 535 A. Tavas and Nafas
    codeforces 534 A. Exam
    hust新人赛模拟 20150407 H
    hust新人赛模拟20150407 F
    hust新人赛模拟20150407 C
    hust新人赛模拟20150407 A
    [dp专题]hdu 1160 FatMouse's Speed
    [dp专题]hdu 1260 tickets
    [dp专题]G免费馅饼
    迷宫问题(bfs+记录路径)
  • 原文地址:https://www.cnblogs.com/wlemory/p/4678933.html
Copyright © 2011-2022 走看看