| 제목 | 트랜젝션 질문입니다 | ||
|---|---|---|---|
| 카테고리 | CI 2, 3 | ||
| 글쓴이 | 책상다리 | 작성시각 | 2021/03/05 13:12:43 | 
| 
                         | 
                |||
                        
	function notice_write($arrays)
	{
		$this->db->trans_begin();
        $this->db->set('successflag',$arrays['successflag']);
        $this->db->set('delflag',$arrays['delflag']);
        $this->db->set('msg',$arrays['msg']);
        $this->db->set('paycode',$arrays['paycode']);
        $this->db->where('idx',$arrays['idx']);
        $this->db->update('notice_table');
		$this->db->set('id',$arrays['id']);
		$this->db->set('price',$arrays['price']);
		$this->db->set('info',$arrays['info']);
		$this->db->set('successflag',$arrays['successflag']);
		$this->db->set('dRegTime',$arrays['dRegTime']);
		$this->db->set('tRegTime',$arrays['tRegTime']);
		$this->db->insert('PointUse');
		$this->db->set('nTotalUseDP','nTotalUseDP + ' . $arrays['price'], false);
		$this->db->set('dtLastUse',$arrays['last_date']);
		$this->db->where('id',$arrays['id']);
		$this->db->update('PointMain');
		if ($this->db->trans_status() === FALSE)
		{
		    $this->db->trans_rollback();
		    return false;
		}
		else
		{
		    $this->db->trans_commit();
		    return true;
		}
    }
 위와같이 트랜젝션 구성했을때, 커밋이 실패해도 롤백이 되지 않고, 나머지 구문이 커밋되면서 true로 넘어가고 있습니다; 예를들어 첫번째 update구문에 이상한 값을 넣어서 update가 실행되지 않아도 나머지 두개의 구문이 커밋되고 그대로 처리가 됩니다. 일단은 메뉴얼에 사용법을 토대로 만들었는데 제 사용방법이 잘못된건지 궁금합니다 엑티브레코드로 해서 그런가 시험삼아 $this->db->query('query'); 이런식으로 3개 똑같이 구성해서 시도해봤는데도 마찬가지였습니다;  | 
                |||
| 다음글 | Pagination 사용시 한글 깨지는 문제가 있어 문... (2) | ||
| 이전글 | CI 4.1.1 서버 셋팅 오류 관련 문의드립니다. (7) | ||
| 
                             
                                변종원(웅파)
                                /
                                2021/03/05 13:26:16 /
                                추천
                                0
                             
                             | 
                    
| 
                             
                                PureAni
                                /
                                2021/03/05 13:34:37 /
                                추천
                                0
                             
                            update 시 where 에 없는값.. 즉, DB에 없어서 update 가 안되는 where 값을 넣었다는거죠? 그러면 정상적인 실행맞습니다.  | 
                    
| 
                             
                                책상다리
                                /
                                2021/03/05 13:38:00 /
                                추천
                                0
                             
                            변종원님//아.........;;; 감사합니다. PureAni님//감사합니다.  | 
                    
뭔가 잘못 생각하시고 있는 것 같네요.
업데이트 구문 자체가 틀려서 업데이트 액션 자체가 실행이 안됐을 때 트랜잭션이 실패하는 것이지
올바른 구문에 업데이트 조건이 맞지 않아 업데이트가 안된 것은 정상상태입니다.
원하시는 상황을 구현하려면 affected_rows()함수로 업데이트가 됐는지 여부에 따라 다음 액션을 실행하게 해야 합니다.