ZF-5830: Zend_Db_Table_Select doesn't allow use of $select->columns('..')

Issue Type: Bug Created: 2009-02-18T12:14:17.000+0000 Last Updated: 2012-07-21T15:28:16.000+0000 Status: Closed Fix version(s): Reporter: Michael Rehbein (tech13) Assignee: Ralph Schindler (ralph) Tags: - Zend_Db_Table

Related issues: - ZF-3239

Attachments: - Table_Select.patch


Zend_Db_Table_Select doesn't allow use of $select->columns('..')

code fragment: $tbl = new Category_Table(); $select = $tbl->select()->columns('id');

Results: Zend_Db_Select_Exception: No table has been specified for the FROM clause in /usr/share/php/Zend-1.7.5/Db/Select.php on line 224

Expected: Zend_Db_Table_Select should already have a table when created from a Zend_Db_Table_Abstract.

Bug?: Zend_Db_Table_Select's from clause isn't set till assemble()


Posted by julien PAULI (doctorrock83) on 2009-02-20T05:29:03.000+0000


I already told Zend (ralph probably) that a Zend_Db_Table_Select should be given it's own table in the from clause, just after creating it. It's not logic to have a Zend_Db_Table_Select entirely empty at creation, it should at least contains its own table as its first from clause.

See :

<pre class="highlight">
// that's not logic
$table->fetchall($table->select()->from($table, array('my', 'cols')));

<pre class="highlight">
// that seems more logic
$table->fetchall($table->select()->columns(array('my', 'cols')));

Posted by Michael Rehbein (tech13) on 2009-02-26T10:27:28.000+0000

Turns out just adding the from in the setTable doesn't act as expected.

$select = $tbl->select()->columns('id'); would still include an all columns in the select.

'select table.* , from table'

Attached is a patch I used to fix the bug for me.

short version: Added a different version of the columns method for the class that includes the 'from' on demand. If a column not from the primary table is requested, it will throw an error. Seemed logical since the assemble for Zend_Db_Table_Select would throw for any columns not in the primary table.

Posted by Jurrien Stutterheim (norm2782) on 2009-03-11T20:29:47.000+0000

This issue is already known as ZF-3239. It's a tricky one and hard solve without BC issues. A real patch probably won't be available until ZF 2.0, where we can break the BC a bit. Although I would love to be proven wrong in this case ;)

Posted by Ralph Schindler (ralph) on 2009-08-25T17:15:30.000+0000

Since 1.9 there has been a feature in place that allowed select() to be called on a table with that will load the from part into the object.

Please see here, and the api doc here

I think it might fix this problem.


Posted by Michael Rehbein (tech13) on 2010-02-22T11:02:44.000+0000

Was fixed as of 1.9. Marking issue closed.

Posted by Enrico Hofmann (ehofmann) on 2012-04-25T12:59:20.000+0000

I got this error, today on Version 1.10.6.

Posted by Nico Mebes (nicomebes) on 2012-06-08T12:34:50.000+0000

Got the same error today. Version 1.11.5

Posted by Crispen Smith (crispen) on 2012-07-21T15:28:16.000+0000

Also using Version 1.11.5, replicated the issue using this code:

public function fetchThumbnailBarContents()
    $table = $this->getTable();
    $select = $table->select()->columns('index_image')->where('status=1')->order('created')->limit(9);
    return $table->fetchAll($select);


public function getTable()
    if (null === $this->_table) {
        require_once APPLICATION_PATH . '/models/DbTable/IndexImages.php';
        $this->_table = new Model_DbTable_IndexImages;
    return $this->_table;

All other pulls from the same pattern work fine, but when I try to specify just the index_images column I get error message:

Message: No table has been specified for the FROM clause

Luckily enough, it's a lightweight table and I was just doing minor performance tuning, but it would be nice if this could be resolved.

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.