문제

I am trying to execute a bunch of statements inserting into multiple tables within a transaction, but when I call for a rollback, everything returns without error but the data is inserted!

//Returns "YES"
$supports = mysql_query( "SELECT SUPPORT FROM INFORMATION_SCHEMA.ENGINES WHERE ENGINE = 'InnoDB'" );

//Start transaction
mysql_query( "SET AUTOCOMMIT=0" );
mysql_query( "START TRANSACTION" );

//Do some inserts
mysql_query( "INSERT INTO ...." );
$lastId = mysql_query( "SELECT LAST_INSERT_ID() as lastId" );
mysql_query( "INSERT INTO...." );

//Try to rollback
mysql_query( "ROLLBACK" );
mysql_query( "SET AUTOCOMMIT=1" );

The tables are all created as InnoDB tables. Running SHOW CREATE TABLE <table_name> shows all tables are created as:

CREATE TABLE `mytable` (
    ...the columns...
) ENGINE=InnoDB AUTO_INCREMENT=61 DEFAULT CHARSET=latin1

What am I doing wrong?

도움이 되었습니까?

해결책

@eggyal led to the answer. My START TRANSACTION was inside a loop instead of outside it, so it was starting multiple transactions and only rolling back the last one.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top