簡體   English   中英

ZF2表網關選擇

[英]ZF2 tableGateway select

我從ZendSkeletonApplication開始,並添加了一個擴展Zend \\ Db \\ TableGateway \\ TableGateway的模型。 我有以下方法:

public function findByType($type) {
    $rowset = $this->select('type' => $type);
    return $rowset;
}

這有效,但現在如果我這樣做:

$foo = $table->findBytype('foo');
$bar = $table->findBytype('bar');

第一個有效,它執行的查詢是:

SELECT * FROM table WHERE 'type' = 'foo'

但是,第二個執行以下查詢:

SELECT * FROM table WHERE 'type' = 'foo' AND 'type' = 'bar'

這是預期的行為嗎? 如果是這樣,我怎么第二次調用該方法執行以下查詢:

SELECT * FROM table WHERE 'type' = 'bar'

提前致謝!

應該在tableGateway中使用select,例如:

$select = $this->getSql()->select();
$select->where(array('type' => 'foo'))
    ->where(array('type' => 'bar'));
$rowset = $this->selectWith($select);

下次調用select()時,它將重置where()參數。

在我的博客中查看更多用法: http : //avnpc.com/pages/advanced-database-select-usage-in-zf2

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM