mysql事务备份

1.http://wasabi.javaeye.com/blog/180162

1.“; mysql_query(‘ROLLBACK’) or exit(mysql_error());//判断当执行失败时回滚 exit; } $ssql1=”insert into pf_item values(’21’,’hell’,’10’)”; //执行sql 2 if(!mysql_query($ssql1)){ echo $ssql1.mysql_errno().”:”.mysql_error().”
“; mysql_query(‘ROLLBACK’) or exit(mysql_error());//判断当执行失败时回滚 exit; } mysql_query(‘COMMIT’) or exit(mysql_error());//执行事务 mysql_close($LinkID); ?>

2.

mysql_query(“BEGIN”);//开始一个事务 mysql_query(“SET AUTOCOMMIT=0″); //设置事务不自动commit $insert=”INSERT INTO userinfo VALUES (‘aa12′,’aa’,’1′,’aaa’)”; mysql_query($insert); mysql_query(“COMMIT”);//非autocommit模式,必须手动执行COMMIT使操作生效 //mysql_query(“SET AUTOCOMMIT=0″); $insert=”INSERT INTO userinfo VALUES (‘aa20′,’aa’,’1′,’aaa’)”; $insert=”INSERT INTO userinfo VALUES (‘aa8′,’aa’,’1′)”; //mysql_query(“COMMIT”); if(mysql_num_rows==0) mysql_query(“ROLLBACK”);//非autocommit模式,执行ROLLBACK使事务操作无效 else echo “ok”; //mysql_query(“CLOSE”); mysql_query(“SET AUTOCOMMIT=1″);//恢复autocommit模式 $insert=”INSERT INTO userinfo VALUES (‘aa15′,’aa’,’1′,’aaa’)”; mysql_query($insert);//不需要手动执行COMMIT就可以使事务操作生效

执行BEGIN之后,其作用同set autocommit=0,而且之后设置set autocommit=0或1时无效。所以,为使操作清楚,一般不使用BEGIN。

3.mysql事务与行锁

http://www.611530.com/PC/wangzhan/200910/2220.html

4. http://hi.baidu.com/cuihu0706/blog/item/1dd6ccb1621c355709230278.html

5.各种锁的类型: http://www.d5s.cn/archives/93

6.CI中的事务: http://xinbituya.blogbus.com/logs/21820416.html http://codeigniter.org.cn/user_guide/database/transactions.html

Leave a Reply

Your email address will not be published. Required fields are marked *