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