2010-04-29 3 views
2

내가 이런 식으로 뭔가를하고 싶은 경우에 조건 :Zend_Db_Select : 재편성 절

$select = $myTbl->select() 
->from('download_log') 
->joinLeft(...... etc........ 
->joinLeft(...... etc........ 
->joinLeft(...... etc........); 

//Filter all configured bots (Google, Yahoo, etc.) 
if(isset($this->_config->statistics->bots)){ 
$bots = explode(',',$this->_config->statistics->bots); 
foreach ($bots as $bot){ 
    $select = $select->where("user_agent NOT LIKE '%$bot%'"); 
} 
} 

$select = $select->where("download_log.download_log_ts BETWEEN '".$start_date." 00:00:00' AND '".$end_date." 23:59:59'"); 

그러나 아웃풋이 쿼리 때문에 orWhere 조항의 정확하지가 독특하고 절에 함께 그룹화되지 않습니다. 한 쌍의 괄호 안에 NOT LIKE 절을 재 그룹화하는 것이 가능한지 알고 싶습니다.

나의 현재 대안은 다음과 같습니다

//Filter all configured bots (Google, Yahoo, etc.) 
    if(isset($this->_config->statistics->bots)){ 
    $bots = explode(',',$this->_config->statistics->bots); 
    foreach ($bots as $bot){ 
    $stmt .= "user_agent NOT LIKE '%$bot%' AND "; 
    } 
    $stmt = substr($stmt,0,strlen($stmt)-4); //remove the last OR 
    $select = $select->where("($stmt)"); 
    } 

감사합니다!

답변

0

귀하의 현재 대안이 최선의 선택 인 것으로 보입니다. 여기에 약간 변경 버전 느릅 나무 적절한 $ 봇에게

$botWhere = ''; 
foreach ($bots as $bot){ 
    $botWhere .= $myTbl->getAdapter()->quoteInto('user_agent NOT LIKE ? AND ', "%$bot%"); 
} 
$botWhere = trim($botWhere, ' AND '); 
$select = $select->where($botWhere); 
0

Zend_Db_Select은 찾고자하는 orWhere 절을 지원합니다.

1

감사에 대비해 아무것도 나쁜 전표에 인용 사용합니다입니다! 나는 그것을 마침내했다 :

//Filter all configured bots (Google, Yahoo, etc.) 
if(isset($this->_config->statistics->bots)){ 
     $bots = explode(',',$this->_config->statistics->bots); 
     foreach ($bots as $bot){ 
       $stmt .= $myTbl->getAdapter()->quoteInto("user_agent NOT LIKE ? AND ",%$bot%); 
     } 
     $stmt = trim($stmt, ' AND '); //remove the last AND 
     $stmt .= 'OR user_agent IS NULL'; 
     $select = $select->where("($stmt)"); 
}