Home  >  Article  >  Backend Development  >  Laravel的事务处理求解.

Laravel的事务处理求解.

WBOY
WBOYOriginal
2016-06-06 20:24:561449browse

<code>public function store(Request $request, $id)
{
    $externalAccount = ExternalAccounts::find($id);
    DB::beginTransaction();
    try {
        $externalAccount->fund_number = 999;
        $externalAccount->capital_balance = 'kjhkjhkj';
        $externalAccount->save();
        DB::commit();
    } catch (Exception $e){
       DB::rollback();
       throw $e;
    }
}

第一次用Laravel。。
capital_balance字段为int类型,我故意传进去字符串类型,这样写入肯定会出错的。
但是上面的fund_number居然写入成功了,没有回滚= =。。
求老司机解答。。
mysql引擎没错,是InnoDB。</code>

回复内容:

<code>public function store(Request $request, $id)
{
    $externalAccount = ExternalAccounts::find($id);
    DB::beginTransaction();
    try {
        $externalAccount->fund_number = 999;
        $externalAccount->capital_balance = 'kjhkjhkj';
        $externalAccount->save();
        DB::commit();
    } catch (Exception $e){
       DB::rollback();
       throw $e;
    }
}

第一次用Laravel。。
capital_balance字段为int类型,我故意传进去字符串类型,这样写入肯定会出错的。
但是上面的fund_number居然写入成功了,没有回滚= =。。
求老司机解答。。
mysql引擎没错,是InnoDB。</code>

我估计是mysql的坑,你拿生成好的sql直接到mysql里面去执行一下看看

Statement:
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