1¡¢ÓÃbegin,rollback,commitÀ´ÊµÏÖ
begin ¿ªÊ¼Ò»¸öÊÂÎñ
rollback ÊÂÎñ»Ø¹ö
commit ÊÂÎñÈ·ÈÏ
2¡¢Ö±½ÓÓÃsetÀ´¸Ä±ämysqlµÄ×Ô¶¯Ìύģʽ
MYSQLĬÈÏÊÇ×Ô¶¯Ìá½»µÄ£¬Ò²¾ÍÊÇÄãÌá½»Ò»¸öQUERY£¬Ëü¾ÍÖ±½ÓÖ´ÐУ¡ÎÒÃÇ¿ÉÒÔͨ¹ý
set autocommit=0 ½ûÖ¹×Ô¶¯Ìá½»
set autocommit=1 ¿ªÆô×Ô¶¯Ìá½»
À´ÊµÏÖÊÂÎñµÄ´¦Àí¡£
µ±ÄãÓà set autocommit=0 µÄʱºò£¬ÄãÒÔºóËùÓеÄSQL¶¼½«×öΪÊÂÎñ´¦Àí£¬Ö±µ½ÄãÓÃcommitÈ·ÈÏ»òrollback½áÊø¡£
×¢Òâµ±Äã½áÊøÕâ¸öÊÂÎñµÄͬʱҲ¿ªÆôÁ˸öеÄÊÂÎñ£¡°´µÚÒ»ÖÖ·½·¨Ö»½«µ±Ç°µÄ×÷Ϊһ¸öÊÂÎñ£¡
¸öÈËÍƼöʹÓõÚÒ»ÖÖ·½·¨£¡
MYSQLÖÐÖ»ÓÐINNODBºÍBDBÀàÐ͵ÄÊý¾Ý±í²ÅÄÜÖ§³ÖÊÂÎñ´¦Àí£¡ÆäËûµÄÀàÐÍÊDz»Ö§³ÖµÄ£¡
***£ºÒ»°ãMYSQLÊý¾Ý¿âĬÈϵÄÒýÇæÊÇMyISAM,ÕâÖÖÒýÇæ²»Ö§³ÖÊÂÎñ£¡Èç¹ûÒªÈÃMYSQLÖ§³ÖÊÂÎñ£¬¿ÉÒÔ×Ô¼ºÊÖ¶¯ÐÞ¸Ä:
·½·¨ÈçÏ£º1.ÐÞ¸Äc:\appserv\mysql\my.iniÎļþ£¬ÕÒµ½skip-InnoDB,ÔÚÇ°Ãæ¼ÓÉÏ#£¬ºó±£´æÎļþ¡£
2.ÔÚÔËÐÐÖÐÊäÈ룺services.msc,ÖØÆômysql·þÎñ¡£
3.µ½phpmyadminÖУ¬mysql->show engines;(»òÖ´ÐÐmysql->show variables like 'have_%'; ),²é¿´InnoDBΪYES,¼´±íʾÊý¾Ý¿âÖ§³ÖInnoDBÁË¡£
Ò²¾Í˵Ã÷Ö§³ÖÊÂÎñtransactionÁË¡£
4.ÔÚ´´½¨±íʱ£¬¾Í¿ÉÒÔΪStorage EngineÑ¡ÔñInnoDBÒýÇæÁË¡£Èç¹ûÊÇÒÔÇ°´´½¨µÄ±í£¬¿ÉÒÔʹÓÃmysql->alter table table_name type=InnoDB;
»ò mysql->alter table table_name engine=InnoDB;À´¸Ä±äÊý¾Ý±íµÄÒýÇæÒÔÖ§³ÖÊÂÎñ¡£
/*************** transaction--1 ***************/ $conn = mysql_connect('localhost','root','root') or die ("Êý¾ÝÁ¬½Ó´íÎó!!!"); mysql_select_db('test',$conn); mysql_query("set names 'GBK'"); //ʹÓÃGBKÖÐÎıàÂë; //¿ªÊ¼Ò»¸öÊÂÎñ mysql_query("BEGIN"); //»òÕßmysql_query("START TRANSACTION"); $sql = "INSERT INTO `user` (`id`, `username`, `sex`) VALUES (NULL, 'test1', '0')"; $sql2 = "INSERT INTO `user` (`did`, `username`, `sex`) VALUES (NULL, 'test1', '0')";//ÕâÌõÎÒ¹ÊÒâд´í $res = mysql_query($sql); $res1 = mysql_query($sql2); if($res && $res1){ mysql_query("COMMIT"); echo 'Ìá½»³É¹¦¡£'; }else{ mysql_query("ROLLBACK"); echo 'Êý¾Ý»Ø¹ö¡£'; } mysql_query("END"); /**************** transaction--2 *******************/ /*·½·¨¶þ*/ mysql_query("SET AUTOCOMMIT=0"); //ÉèÖÃmysql²»×Ô¶¯Ìá½»£¬Ðè×ÔÐÐÓÃcommitÓï¾äÌá½» $sql = "INSERT INTO `user` (`id`, `username`, `sex`) VALUES (NULL, 'test1', '0')"; $sql2 = "INSERT INTO `user` (`did`, `username`, `sex`) VALUES (NULL, 'test1', '0')";//ÕâÌõÎÒ¹ÊÒâд´í $res = mysql_query($sql); $res1 = mysql_query($sql2); if($res && $res1){ mysql_query("COMMIT"); echo 'Ìá½»³É¹¦¡£'; }else{ mysql_query("ROLLBACK"); echo 'Êý¾Ý»Ø¹ö¡£'; } mysql_query("END"); //ÊÂÎñ´¦ÀíÍêʱ±ðÍü¼Çmysql_query("SET AUTOCOMMIT=1");×Ô¶¯Ìá½» /******************¶ÔÓÚ²»Ö§³ÖÊÂÎñµÄMyISAMÒýÇæÊý¾Ý¿â¿ÉÒÔʹÓñíËø¶¨µÄ·½·¨£º********************/ //MyISAM & InnoDB ¶¼Ö§³Ö, /* LOCK TABLES¿ÉÒÔËø¶¨ÓÃÓÚµ±Ç°Ïß³ÌµÄ±í¡£Èç¹û±í±»ÆäËüÏß³ÌËø¶¨£¬ÔòÔì³É¶ÂÈû£¬Ö±µ½¿ÉÒÔ»ñÈ¡ËùÓÐËø¶¨ÎªÖ¹¡£ UNLOCK TABLES¿ÉÒÔÊͷű»µ±Ç°Ï̱߳£³ÖµÄÈκÎËø¶¨¡£µ±Ï̷߳¢²¼ÁíÒ»¸öLOCK TABLESʱ£¬»òµ±Óë·þÎñÆ÷µÄÁ¬½Ó±»¹Ø±Õʱ£¬ËùÓÐÓɵ±Ç°Ïß³ÌËø¶¨µÄ±í±»Òþº¬µØ½âËø¡£ */ mysql_query("LOCK TABLES `user` WRITE");//Ëøס`user`±í $sql = "INSERT INTO `user` (`id`, `username`, `sex`) VALUES (NULL, 'test1', '0')"; $res = mysql_query($sql); if($res){ echo 'Ìá½»³É¹¦¡£!'; }else{ echo 'ʧ°Ü!'; } mysql_query("UNLOCK TABLES");//½â³ýËø¶¨
ÍƼöÐÅÏ¢
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- php³£ÓÃÕýÔò±í´ïʽ
- phpÐÔÄܼà²âÄ£¿éXHProf
- ÈÃCI¿ò¼ÜÖ§³Öservice²ã
- ʹÓÃPHPÉú³É´øLOGOµÄ¸öÐÔ»¯¶þάÂëͼÏñ
- ¹ØÓÚCodeIgniterÄã¿ÉÄܲ»ÖªµÀµÄ5¸ö֪ʶµã
- Memcache ºÁÃ뼶³¬Ê±¼°ÆäËû³£¼ûÎÊÌâ»ã×Ü
- [PHP±Ê¼Ç]PHPQueryÒ»¸ö´¦ÀíDOMµÄÀûÆ÷
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- PHP»ñÈ¡Óû§µÄÕæʵIP£¬²¢ÅжÏÊÇ·ñÄÚÍøIP
- PHP ´íÎóÈÕÖ¾ error_log
- ÀûÓÃbigpipe»úÖÆʵÏÖÒ³ÃæÄ£¿éµÄÒì²½äÖȾ chunked¼¼Êõ
- php¿ØÖÆÎļþÏÂÔØËÙ¶È
- js + php ¶ÁÈ¡¡¢²¥·ÅÊÓƵÁ÷ ¼æÈÝfirefox£¬c....
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- UNICODE Óë UTF-8 µÄ¹Øϵ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- phpʹÓÃmb_detect_encoding¼ì²â×Ö·û´®±àÂë
ÆÀÂÛ