MySQL/PHP 事务行为 [英] MySQL / PHP transaction behavior

查看:35
本文介绍了MySQL/PHP 事务行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定:

mysql_query("START TRANSACTION");
mysql_query("UPDATE foo = 'bar'");
die();

die() 在我可以 COMMITROLLBACK 之前停止事务.查看我的表,似乎没有发生更新,但是如果我稍后在另一个脚本中运行查询,它们是否仍然是初始事务的一部分?在我 COMMITROLLBACK 之前,交易是否仍然打开"?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆