YII Thing Invalid problem

Source: Internet
Author: User
Tags yii
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!!!
  • 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.