Zend_Db_Table_Select 如何工作?
我试图弄清楚如何正确使用 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());
I'm trying to figure out how to use Zend_Db_Table_Abstract correctly. I want to return just the name
column from my query. Can you please explain what's wrong with the following code?
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());
}
}
Update:
From the example by @Joshua Smith below, I was able to figure out how to use select() to do this correctly:
$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());
您的代码非常接近工作:
http://framework.zend。 com/manual/en/zend.db.table.html
有关特定列选择的信息,请参阅示例 #25;有关使用查找的更多信息,请参阅“按主键查找行”。
Your code is very close to working:
http://framework.zend.com/manual/en/zend.db.table.html
see example #25 for specific column selection and 'Finding Rows by Primary Key' for more about using find.