MySQL/PHP 事务行为 [英] MySQL / PHP transaction behavior
问题描述
给定:
mysql_query("START TRANSACTION");
mysql_query("UPDATE foo = 'bar'");
die();
die()
在我可以 COMMIT
或 ROLLBACK
之前停止事务.查看我的表,似乎没有发生更新,但是如果我稍后在另一个脚本中运行查询,它们是否仍然是初始事务的一部分?在我 COMMIT
或 ROLLBACK
之前,交易是否仍然打开"?
die()
stops the transaction before I can COMMIT
or ROLLBACK
. Looking at my tables, it appears that the update doesn't take place, but if I run queries later in another script, are they still part of that initial transaction? Is the transaction still 'open' until I COMMIT
or ROLLBACK
?
推荐答案
如果 die 终止了与 mysql 的连接,则是,事务关闭.如果您只是将交易搁置一边,尽管您会遇到麻烦.
If die kills the connection to mysql then yes, the transaction is closed. If you're just leaving the transaction hanging though you're going to get in trouble.
我建议确保事务和提交在同一个 mysql_query 中,如果人类可能确保它确实发生.
I would recommend making sure that the transaction and the commit are in the same mysql_query if at all humanly possible to ensure that it actually happens.
这篇关于MySQL/PHP 事务行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!