2010-02-06 5 views

답변

1
$firstname = 'alex'; 
$city = 'xx'; 

// AND query 
$select = $adapter->select() 
    ->from('person', array('id', 'firstname', 'lastname', 'city') 
    ->where('firstname = ?', $firstname) 
    ->where('city ?', $city); 


// OR query 
$select = $adapter->select() 
    ->from('person', array('id', 'firstname', 'lastname', 'city') 
    ->where('firstname = ?', $firstname) 
    ->orWhere('city = ?', $city); 

의 예제를 볼 수 있습니다.

1

당신은 더 많은 예제를 볼 수 Zend_Db_Select 설명서를 한 번 봐 Zend.DB manual

// Build this query: 
    // SELECT product_id, product_name, price 
    // FROM "products" 
    // WHERE (price < 100.00 OR price > 500.00) 
    //  AND (product_name = 'Apple') 

    $minimumPrice = 100; 
    $maximumPrice = 500; 
    $prod = 'Apple'; 

    $select = $db->select() 
       ->from('products', 
         array('product_id', 'product_name', 'price')) 
       ->where("price < $minimumPrice OR price > $maximumPrice") 
       ->where('product_name = ?', $prod); 
+0

이 부분에서 "price <$ minimumPrice OR price> $ maximumPrice"변수는 새 니타이션되지 않습니다. 이것은 SQL 주입으로 이어질 수 있습니다. –

+0

-1 죄송합니다. 예가 설명서에서 나온 것인지 몰랐습니다. 그것은 잘못되었지만 그것은 당신의 잘못이 아닙니다. 질문을 편집하면 투표를 취소 할 수 있습니다. –

+0

한편으로는 올바른 것이지만, 다른 한편으로는 변수가 모두 3 행 전에 정의되고 정수이기 때문에 완전히 안전합니다. 나는 누군가가 선택에만 복사하면 문제가 될 수 있다고 동의한다. 쿼리 작성 방법을 설명하기 위해보다 명확합니다. –

관련 문제