请问 Mysql事务回滚如何写

WBOY
Release: 2016-06-13 13:26:22
Original
1009 people have browsed it

请教 Mysql事务回滚怎么写?
请教 Mysql事务回滚怎么写?
就是俺现在碰到一个问题:论坛扣币项目中,用户支付论坛币的时候如果突然断网、电脑死机、停电、等其它自然灾害时,导致本次交易没有成功(即用户的币已经扣掉了,但是服务器数据库中没有消费记录等其它情况),这种情况是用Mysql事务回滚处理吗?代码怎么写?还有别的办法吗?

――――期待前辈高手详解!

------解决方案--------------------
没有commit是不会生效的, 回滚是取消的意思, 不是提交的意思.
------解决方案--------------------
这个也没什么好讲的,网上大把的教程,找了一段给你自测,尝试着把sql写错然后看看效果

PHP code
mysql_query("BEGIN"); //或者mysql_query("START TRANSACTION"); $sql = "INSERT INTO ..."; $sql2 = "INSERT INTO ..."; $res = mysql_query($sql); $res1 = mysql_query($sql2); if($res && $res1){ mysql_query("COMMIT"); echo '提交成功。'; }else{ mysql_query("ROLLBACK"); echo '数据回滚。'; } mysql_query("END"); 
Copy after login
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