All the gods, get started. PHP programmers asking for help
Yii Things
Official wording:
$transaction = $connection->begintransaction (); Try { $connection->createcommand ($sql 1)->execute (); $connection->createcommand ($sql 2)->execute (); .... Other SQL executions $transaction->commit (); } catch (Exception $e) { $transaction->rollback (); }
The wording of your own package:
Description: $this->getdb () is the $connection object that is acquired by the parent class through Yii
I just put the $connection object into the DB layer when I instantiate it, and then the DB layer makes the operation of adding and checking.
But in the DB layer, when the excuse () method is inserted directly into the database, things do not work, solve!!!
Service Layer
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 (); }
Reply to discussion (solution)
Waiting for a reply
What about people, people ...
But I don't understand what your code is doing.
However, it is important to note that transactions are only valid in the same connection
Yii's database is based on PDO, and each new PDO will generate a fresh connection (this is different from the database extension of the discrete function)
But I don't understand what your code is doing.
However, it is important to note that transactions are only valid in the same connection
Yii's database is based on PDO, and each new PDO will generate a fresh connection (this is different from the database extension of the discrete function)
Thank you moderator, has been resolved.
My approach is to implement things by invoking multiple business db in the service. The idea should be correct, the specific error has been solved.
After the troubleshooting was found to be a database engine problem, I want to manipulate that table type do not know how to become MyISAM.
MyISAM and InnoDB explain InnoDB and MyISAM are the two most common table types that many people use when using MySQL, both of which have pros and cons, depending on the application. The basic difference is that the MyISAM type does not support advanced processing such as transaction processing, and InnoDB type support. Tables of the MyISAM type emphasize performance, which is performed more quickly than the InnoDB type.
Toss a morning, just start also consider the database engine may be the problem, but the probability is relatively small ignored, we still have to be careful AH!!!