Completed
Push — 6.0 ( be0b6e...c47dd5 )
by liu
06:54 queued 10s
created

Transaction   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 44
ccs 0
cts 10
cp 0
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A startTrans() 0 3 1
A transaction() 0 3 1
A commit() 0 3 1
A rollback() 0 3 1
1
<?php
2
// +----------------------------------------------------------------------
3
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
4
// +----------------------------------------------------------------------
5
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
6
// +----------------------------------------------------------------------
7
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
8
// +----------------------------------------------------------------------
9
// | Author: liu21st <[email protected]>
10
// +----------------------------------------------------------------------
11
declare (strict_types = 1);
12
13
namespace think\db\concern;
14
15
/**
16
 * 事务支持
17
 */
18
trait Transaction
19
{
20
21
    /**
22
     * 执行数据库事务
23
     * @access public
24
     * @param callable $callback 数据操作方法回调
25
     * @return mixed
26
     */
27
    public function transaction(callable $callback)
28
    {
29
        return $this->connection->transaction($callback);
30
    }
31
32
    /**
33
     * 启动事务
34
     * @access public
35
     * @return void
36
     */
37
    public function startTrans(): void
38
    {
39
        $this->connection->startTrans();
40
    }
41
42
    /**
43
     * 用于非自动提交状态下面的查询提交
44
     * @access public
45
     * @return void
46
     * @throws PDOException
47
     */
48
    public function commit(): void
49
    {
50
        $this->connection->commit();
51
    }
52
53
    /**
54
     * 事务回滚
55
     * @access public
56
     * @return void
57
     * @throws PDOException
58
     */
59
    public function rollback(): void
60
    {
61
        $this->connection->rollback();
62
    }
63
64
}
65