think-orm icon indicating copy to clipboard operation
think-orm copied to clipboard

There is no active transaction 错误出现的原因

Open doesDWQ opened this issue 4 years ago • 1 comments

下面这段代码不够严谨,希望能够处理一下 image

PDOConnection

public function transaction(callable $callback) { $this->startTrans();

    try {
        $result = null;
        if (is_callable($callback)) {
            $result = $callback($this);
        }

        $this->commit();
        return $result;
    } catch (\Exception | \Throwable $e) {
        $this->rollback();
        throw $e;
    }
}

这里面的 $this->rollback(); 这个一旦抛错,实际的错误就看不到了,其实实际的错误是 SQLSTATE[HY000]: General error: 1364 Field 'accessName' doesn't have a default value

doesDWQ avatar Jan 28 '21 03:01 doesDWQ

自行分拆步骤吧,这种更具体的处理逻辑还是自己写的好

lzlin avatar Sep 14 '21 06:09 lzlin