Mysql transaction : commit and rollback

前端 未结 2 921
感动是毒
感动是毒 2021-01-01 03:16

I updated my PhpMyAdmin database engine from MyISAM to INNODB to allow rollback.

This is my SQL query :

START TRANSACTION;
UPDATE jkm_content SET st         


        
2条回答
  •  爱一瞬间的悲伤
    2021-01-01 04:18

    1) All changes you make are visible within the same transaction. If you do

    START TRANSACTION;
    INSERT INTO MyTable VALUES ('Hi there');
    SELECT * FROM MyTable;
    

    your output will include the 'Hi there'. But if you start a second database-connection the new row won't be displayed until you commit your transaction from within the first connection. Try playing with this using two database-connections using the command-line.

    You're not seeing the effect in your website because you can't have the same transaction within two database-connection (a new db-connection will be made at the beginning of your request).

    2) All transactions that aren't committed will be rolled back when the connection with the database is closed. So if these are your only two queries, there are no difference. However there is a difference between

    START TRANSACTION;
    INSERT INTO MyTable VALUES ('This one would be discarded on rollback');
    ROLLBACK;
    INSERT INTO MyTable VALUES ('This one will be permanent because not within transaction');  
    

    3) Yes, these are all the same.

提交回复
热议问题