Home > Backend Development > PHP Tutorial > yii2 transactions are not rolled back

yii2 transactions are not rolled back

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-06 13:52:34
Original
1261 people have browsed it

yii2 transactions are not rolled back
The transaction is not rolled back after the sub-table is saved. There is still a piece of data in the main table. Please solve it. Thank you!

Reply content:

yii2 transactions are not rolled back
The transaction is not rolled back after the sub-table is saved. There is still a piece of data in the main table. Please solve it. Thank you!

There is a problem with your code logic, and commit will eventually be called

You should ensure that when $transaction->rollback() is executed, the following code will jump out of execution

<code>$t = \Yii::$app->db->beginTransaction();
try{
    if($orderModel->save()){
        ...
        if(!$re){
            throw new Exception('错误信息');
        }
        ...
    }
    $t->commit();
}catch(Excetption $e){
    $t->rollback();
    throw new Exception($e->getMessage());
}</code>
Copy after login

Also check whether the storage engine of your table is InnoDB

Are you sure the code can run?

It feels like if is missing a curly brace

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template