MySQL AUTOCOMMIT status while using BEGIN and START TRANSACTION -


i need use transaction in project on mysql. i'm not sure if have use mysql_query("set autocommit=0"); or not.
know have 2 options:

  1. begin
  2. start transaction

also have heard 1 of both items not need using autocommit = 0.
please me know when have use autocommit = 0 actually, begin or start transaction?

thank you.

as explained in the manual:

by default, mysql runs autocommit mode enabled. means execute statement updates (modifies) table, mysql stores update on disk make permanent. change cannot rolled back.

to disable autocommit mode implicitly single series of statements, use start transaction statement:

start transaction; select @a:=sum(salary) table1 type=1; update table2 set summary=@a type=1; commit; 

with start transaction, autocommit remains disabled until end transaction commit or rollback. autocommit mode reverts previous state.

the manual goes on say:

to disable autocommit mode explicitly, use following statement:

set autocommit=0; 

after disabling autocommit mode setting autocommit variable zero, changes transaction-safe tables (such innodb or ndbcluster) not made permanent immediately. must use commit store changes disk or rollback ignore changes.

autocommit session variable , must set each session. disable autocommit mode each new connection, see description of autocommit system variable @ section 5.1.3, “server system variables”.

begin , begin work supported aliases of start transaction initiating transaction. start transaction standard sql syntax , recommended way start ad-hoc transaction.


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -