Home > Backend Development > PHP Tutorial > mysql事宜执行完毕,需要恢复autocommit=1吗

mysql事宜执行完毕,需要恢复autocommit=1吗

WBOY
Release: 2016-06-13 12:22:04
Original
1133 people have browsed it

mysql事务执行完毕,需要恢复autocommit=1吗?

set autocommit =0;     //关闭自动提交
start transaction;       //开启一个事务;
---------------------......
commit;                  //正式提交事务;事务结束;


commit之后,还要把set autocommit =1恢复吗?  我看别人的案例都没恢复,commit会自动恢复?
------解决思路----------------------
autocommit 默认为1,即自动提交事务

你 set autocommit =0 是为了关闭自动提交,显然这是你个人的行为
所以事务结束后,是否需要将 autocommit 还原成 1,自然也是你的个人行为

你只要重新连接数据库, autocommit  依然是 1,并不管你上次操作后的状态。这才是服务器的行为

如果你在执行完一次事务后,还要再执行 100 次事务,你是关闭还是开启事务的自动提交呢?

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template