[英]How does Zend_Db_Table_Select work?
我試圖弄清楚如何正確使用Zend_Db_Table_Abstract。 我只想從查詢中返回name
列。 您能否解釋以下代碼有什么問題?
class Model_DbTable_Foo extends Zend_Db_Table_Abstract
{
protected $_name = 'foo';
public function getFooById($id) {
$select = $this->select(true)->columns('name')->where('id=' . $id);
$row = $this->fetchRow($select);
print_r($row->toArray());
}
}
更新:
從下面@Joshua Smith的示例中,我能夠弄清楚如何使用select()正確執行此操作:
$select = $this->select()
->from($this->_name, 'name') // The 2nd param here could be an array.
->where('id = ?', $id);
$row = $this->fetchRow($select);
print_r($row->toArray());
您的代碼非常接近工作:
class Model_DbTable_Foo extends Zend_Db_Table_Abstract
{
protected $_name = 'foo';
public function getFooById($id) {
$row = $this->find($id)->current();
return $row->name;
}
}
http://framework.zend.com/manual/en/zend.db.table.html有關特定列選擇的信息,請參見示例#25;有關使用find的更多信息,請參見示例“通過主鍵查找行”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.