TIP게시판

제목 [AR] get_where , _cache 사용시 주의점
글쓴이 마냐 작성시각 2009/08/05 17:24:03
댓글 : 3 추천 : 0 스크랩 : 0 조회수 : 14055   RSS
$this->db->get_where('table', array(
  'fld1' => 'val1',
  'fld2' => 'val2'
));

// result
select * from table where fld1 = 'val1' and fld2 = 'val2;


$this->db->where('fld2', 'val2');
$this->db->get_where('table', array(
  'fld1' => 'val1'
));

// result
select * from table where fld2 = 'val2' and fld1 = 'val1';


$this->db->start_cache();
$this->db->where('fld2', 'val2');
$this->db->stop_cache();

$this->db->get_where('table', array(
  'fld1' => 'val1'
));

$this->db->flush_cache();

// result
select * from table where fld2 = 'val2' and fld1 = 'val1';
get_where 에서는 두번째 파라미터로 where 을 사용 할 수 있는데.
이 두번째 파라미터로 넘겨주는 where 값은 where 의 맨 마지막에 연결 됨.

또, $this->db->start_cache(); 로 저장하는 값은 맨 앞에 연결 됨.

$this->db->where('bo_table', 'test');
	
$this->db->start_cache();
$this->db->where('wr_id', '10');
$this->db->stop_cache();

$this->db->get_where('table', array(
  'is_comment' => 1
));

$this->db->flush_cache();

// result
select * from table where and wr_id = '10' bo_table = 'test' and is_comment = 1;
구분 오류를 발생.

----

DB index 순서에 주의.
 다음글 CI 클래스, 헬퍼, 플러그인 개념비교 (4)
 이전글 이클립스 php 사용팁 (7)

댓글

ci세상 / 2009/08/05 17:43:38 / 추천 0
네넹 코딩시 참조하겠습니다.^^
변종원(웅파) / 2009/08/05 18:14:30 / 추천 0

mysql은 where절의 순서에 상관이 없지 않은가요?
 

where a=1 and b=2

간혹 쿼리 날리다보면 순차적으로 검색을 하기를 원하는데 mysql은 where절의 순서에 상관없이
결과를 뿌려주는데 제가 이해를 잘못하고 있는건지.. ^^

마냐님이 올려주신 것은 where절의 순서에 관한 것이 아니라 캐싱과 같이 쓸 경우 에러가
발생할 수 있다는 거죠? ^^

날이 덥다보니... ㅎㅎ 

터프키드 / 2009/08/05 18:14:52 / 추천 0
와~ 좋은팁 감사합니다~