$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 ' +:p rice 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 (':p rice ', $price); $updateStatus = $command->execute (); $command->execute ();
Attention:
- Yii in the operation as above, because there are three SQL statements in $sql caused $command->execute (); not working, here it only detects whether the first SQL is performing properly, The latter two in time wrong can not show through $updatestatus!
- Executing multiple statements in one SQL, unable to transact transaction causes the database not to be updated
Yii transaction operation is not allowed to put multiple SQL inside a SQL