YII is invalid. HELPHELPHELPHELPHELPHELP-php Tutorial

Source: Internet
Author: User
YII: invalid things. HELPHELPHELPHELPHELPHELP. beginner PHP programmers.

Yii thing

Official statement:
       $transaction=$connection->beginTransaction();        try        {            $connection->createCommand($sql1)->execute();            $connection->createCommand($sql2)->execute();            //.... other SQL executions            $transaction->commit();        }        catch(Exception $e)        {            $transaction->rollBack();        }


Self-encapsulated statement:
: $ This-> getDb () is the $ connection object obtained by the parent class through Yii.
I just uploaded the $ connection object to the Db layer during instantiation, and then added, deleted, modified, and queried operations on the Db layer.
But at the DB layer, when the excuse () method is executed, it is directly inserted into the database, and things do not work. solve the problem !!!
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)

Wait for a reply

People, people .....

But do not understand what your code is doing
However, you must note that the transaction is only valid in the same connection.
Yii databases are based on PDO, and new PDO creates new connections every time (this is different from the database extension of discrete functions)

But do not understand what your code is doing
However, you must note that the transaction is only valid in the same connection.
Yii databases are based on PDO, and new PDO creates new connections every time (this is different from the database extension of discrete functions)



Thank you for the solution.
In this way, I want to call the databases of multiple businesses in the service to implement things. The idea should be correct. the specific error has been solved.

After troubleshooting, the problem was found to be a database engine problem. I don't know how to change the table type to MyISAM.


MyISAM and InnoDB explain that InnoDB and MyISAM are the two most common table types when many people use MySQL. the Two table types have their own advantages and disadvantages, depending on the specific application. The basic difference is that the MyISAM type does not support advanced processing such as transaction processing, while the InnoDB type does. MyISAM tables emphasize performance, and the execution speed is faster than that of InnoDB tables.

After a long morning of hard work, we also considered that it may be a database engine problem at the beginning, but we ignored it when the possibility was low. we should be careful later !!!!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.