开发者

Zend framework - Zend_db_table_abtract select()

I want to use select() where I can get just one column without specifying the table name. (Table name is 开发者_运维百科in the $_name var declared in my model.) I tried this:

$select->columns('field');

.. but I get error of "No table has been specified for the FROM clause" - so it looks like it's expecting a table name.

Is there a way of getting just one column?


The error is correct. You need to specify a table you want the field from.

$select->from('table_name', array('field'));


If your class extends the Zend_Db_Table_Abstract, you can use $this->fetchAll() , so no table name need to be specified.

If you still want to use select() pass the $this->_name as you have already declared the value $_name .

$this->select()->from($this->_name);

select() is mainly used to create a select query object, so it cannot guess from which table you are going to though currently you are in the model. It may not be for a query on the same table. So you should pass the table name. For more see http://framework.zend.com/manual/en/zend.db.select.html . All are for different purposes. So you want to use according to your wish.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜