Home  >  Article  >  Backend Development  >  在save()执行之后rollback为什么没有回滚?

在save()执行之后rollback为什么没有回滚?

WBOY
WBOYOriginal
2016-06-06 20:22:551624browse

<code>DB::beginTransaction();
$model = new UserWechat();
$model->unionid = 'od13WwfNk64BQ9ME95S-bzuU7j8A';
$model->save();
DB::rollback();</code>

代码如上,没有按照预期回滚,数据插入了数据库中.
执行原生sql如下, 和预期一致!:

<code>start transaction;
insert into user_wechat (unionid) values('od13WwfNk64BQ9ME95S-bzuU7j8A');
rollback;</code>

难道我错了一万年...

回复内容:

<code>DB::beginTransaction();
$model = new UserWechat();
$model->unionid = 'od13WwfNk64BQ9ME95S-bzuU7j8A';
$model->save();
DB::rollback();</code>

代码如上,没有按照预期回滚,数据插入了数据库中.
执行原生sql如下, 和预期一致!:

<code>start transaction;
insert into user_wechat (unionid) values('od13WwfNk64BQ9ME95S-bzuU7j8A');
rollback;</code>

难道我错了一万年...

你的数据库引擎是InnoDB么?只有InnoDB才支持事务,MyISAM是不支持的哦!

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