Is it necessary to write ROLLBACK if queries fail?(如果查询失败,是否需要编写 ROLLBACK?)
问题描述
我写
mysql_query("SET AUTOCOMMIT=0");
mysql_query("开始交易");
在我编写所有查询之前.然后检查是否所有这些都是真的,然后写:
mysql_query("COMMIT");
但是如果其中一个查询失败,我就通过 COMMIT 查询.那么,如果其中一个查询失败,我真的需要 ROLLBACK 函数吗?因为没有 ROLLBACK 它也可以工作.
谢谢.
I write
mysql_query("SET AUTOCOMMIT=0");
mysql_query("START TRANSACTION");
before I write all queries. Then check if all of them are true and then write:
mysql_query("COMMIT");
But if one of query fails, I just pass COMMIT query. So do I really need ROLLBACK function if one of the queries fail? Because without ROLLBACK it also works.
Thanks.
推荐答案
我想您是在问是否有必要执行 ROLLBACK,因为没有它,提交仍然不会得到应用.这在技术上是正确的,但这只是因为交易仍然处于打开状态,因为您还没有结束它.任何隐式提交事务(例如,启动一个新事务)的行为都将像您运行 COMMIT 一样,这与您想要的相反
I think you're asking if executing ROLLBACK is necessary, since without it the commits still don't get applied. That's technically true, but only because the transaction is still open since you haven't ended it. Anything that implicitly commits the transaction (for example, starting a new transaction) will act as though you ran COMMIT, which is the opposite of what you want
这篇关于如果查询失败,是否需要编写 ROLLBACK?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如果查询失败,是否需要编写 ROLLBACK?


- Laravel 仓库 2022-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01