2010-08-23 5 views
2

나는이 소리가 우스꽝스럽게 들리지만이 주제에 관한 문서는 Google에서 찾을 수 없다는 것을 알고 있습니다.매우 간단합니다. Zend_Db_Table 질문

데이터베이스에서 두 개의 열을 선택하고 싶습니다. Zend_Db_Table 객체를 만들어 내 테이블을 가리 킵니다.

이제 customerId와 name이라는 두 개의 열을 선택하고 싶습니다.

테이블 전체가 아닌 두 열만 선택하려면 어떻게해야합니까?

미리 감사드립니다. 나는 케이크를 구워 주거나 방을 청소합니다.

답변

4
$table->fetchAll(
    $table->select() 
      ->from('table', array('column1', 'column2')) 
); 

그리고 덕분에, 나는 이미 하녀가,

+0

감사 : 문자열과 단일 문자열의 배열

또 다른 예

을 수락! ;) 나는 메일로 그 케이크를 보낼 것이라고 생각한다. – baklap

+0

당신은 더 빨랐습니다 :) –

0
$select = $db->select() 
      ->from(array('t' => 'table'), 
        array('column1', 'column2')); 
$stmt = $db->query($select); 
$result = $stmt->fetchAll(); 
0
$select = $db->select() 
      ->from('products', 
        array('product_id', 'product_name', 'price')); 

당신이에서() 메서드의 두 번째 인수로 원하는 fiels을 통과해야), 첫 번째 테이블은 . 일반적인 SQL 구문에서는 원하는 필드가 먼저 나오기 때문에 혼란 스럽지만 zend db는 모듈 방식으로 쿼리를 작성하려는 경우 매우 유용합니다.

Example #11 Examples of adding columns with the columns() method 
// Build this query: 
// SELECT p."product_id", p."product_name" 
// FROM "products" AS p 

$select = $db->select() 
      ->from(array('p' => 'products'), 'product_id') 
      ->columns('product_name'); 

// Build the same query, specifying correlation names: 
// SELECT p."product_id", p."product_name" 
// FROM "products" AS p 

$select = $db->select() 
      ->from(array('p' => 'products'), 'p.product_id') 
      ->columns('product_name', 'p'); 
      // Alternatively use columns('p.product_name') 
관련 문제