Laravel的事务处理求解.

WBOY
Release: 2016-06-06 20:24:56
Original
1427 people have browsed it

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。
Copy after login
Copy after login

回复内容:

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。
Copy after login
Copy after login

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

Related labels:
source:php.cn
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 Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!