PHP PDO issues cannot be rolled back

Source: Internet
Author: User
PHP PDO transaction cannot be rolled back
Public Function submit () {
try {
$this->begintransaction ();
$this->exec (' Update people set age=2 ');
$this->exec (' INSERT into course (course,num) VALUES ("math", 100) ');
$this->commit ();
}catch (Exception $e) {
$this->rollback ();
}
}

This is the brother's business module, the database engine is InnoDB, but do not know why the SQL if the execution error, PDO always do not rollback, please specify, younger brother grateful ...

------Solution--------------------
Don't try it with try, I don't think it's going to throw an exception.
PHP Code
$this->begintransaction (); $this->exec (' Update people set age=2 ');//$step 1 = mysql_error ();//Your class, change to execute SQL error, Get the error code corresponding to the function $this->exec (' INSERT into course (course,num) VALUES ("math", "+"),//$step 2 = mysql_error (); if (! $step 1 & amp;&! $step 2) {$this->commit ();} else{$this->rollback ();}
------Solution--------------------
Agreed to the 2 floor,
Two statements should only return TRUE or False

  • 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.