2011-01-25 2 views
1

롤백에 문제가있는 응용 프로그램에서 사용 된 코드가 있습니다. 비록 '2 '이 반환 되더라도 잘못된 롤백은 일어나지 않습니다. 즉,'products '테이블이 삭제됩니다. 누구나 왜 작동하지 않거나 어떻게 변경해야하는지 설명 할 수 있습니까? 참고 : 표 5.0mysql에서 MySQL Transaction + PHP 문제

mysql_query('SET AUTOCOMMIT=0;'); 
    mysql_query('START TRANSACTION;'); 
    $sql = 'DROP TABLE '.$this->Product->tablePrefix.'products'; 
    $s1 = mysql_query($sql); 
    $sql = 'RENAME TABLE '.$this->Product->tablePrefix.'temp12212 TO '.$this->Product->tablePrefix.'products'; 
    $s2 =mysql_query($sql); 
    if($s1 && $s2){ 
     mysql_query('COMMIT;'); 
     $this->Session->setFlash('Commit Successful to Database'); 
    }else{ 
     mysql_query('ROLLBACK;'); 
     $this->Session->setFlash('Commit failed due to some errors<br> auto-rollbacked to previous state'); 
    } 

답변

2

DROP TABLE는 암시 적 커밋의 원인이 MySQL의에서 명령 중 하나입니다 이노 디비 engine..I 사용의 MySQL입니다.

http://dev.mysql.com/doc/refman/5.1/en/implicit-commit.html

사용이 대신 : 그들은이 implicit commit의 원인으로

'RENAME TABLE '.$this->Product->tablePrefix.'products TO backup_table 
, '.$this->Product->tablePrefix.'temp12212 TO '.$this->Product->tablePrefix.'products'; 
+0

이름 바꾸기도 NT 형입니다! :-(.. (이름 바꾸기도 암시 적 커밋을 발행합니다.) – Libu

+0

트랜잭션 대신에 두 테이블의 이름을 모두 바꾸려면'RENAME '을 사용하십시오. –

+0

Worked :-) 답장을 보내 주셔서 감사합니다 !!! 'RENAME'은 'START TRANSACTION'& 'COMMIT'에서 사용할 수 없지만 원자 속성으로 인해 대신 사용할 수 있습니다 ... – Libu

1

당신은 DROP TABLE 또는 RENAME TABLE 문을 롤백 할 수 없습니다.

0
I sorted the problem this way instead!!! thanks all for your reply :-) 


$sql = 'DROP TABLE IF EXISTS '.$this->Product->tablePrefix.'temp_backup'; 
     mysql_query($sql); 
     $sql = 'RENAME TABLE '.$this->Product->tablePrefix.'products TO '.$this->Product->tablePrefix.'temp_backup, '.$this->Product->tablePrefix.'temp TO '.$this->Product->tablePrefix.'products'; 
     $status =mysql_query($sql); 
     if($status){ 
      $sql = 'DROP TABLE '.$this->Product->tablePrefix.'temp_backup'; 
      mysql_query($sql); 
      $this->Session->setFlash('Commit Successful to Database'); 
     }else{    
      $this->Session->setFlash('Commit failed due to some errors<br> auto-rollbacked to previous state'); 
     }