ZF-28: Zend_Db_Select::_tableCols() won't select table-specific columns

Issue Type: Bug Created: 2006-06-19T22:52:11.000+0000 Last Updated: 2007-07-05T14:43:06.000+0000 Status: Resolved Fix version(s): - 0.8.0 (21/Feb/07)

Reporter: Zend Framework (zend_framework) Assignee: Bill Karwin (bkarwin) Tags: - Zend_Db_Select

Related issues: Attachments:


Hello Zend,

in your method "Zend_Db_Select::_tableCols()" it won't select table specific columns. I have create a own Db_Select class thats extends your class and i have rewrite this method. Do you change this in the future or it is new ready?

my rewrited method:

<pre class="highlight">
    protected function _tableCols($tbl, $cols) {
        if (is_string($cols)) {
            $cols = explode(',', $cols);
        } else {
            settype($cols, 'array');

        foreach ($cols as $col) {
            $col = trim($col);
            if ($col != '*' && strpos($col, '(')===false) {
                $col = '`'.$col.'`';
            $this->_parts['cols'][] = '`'.$tbl.'`.'.$col;


Posted by Bill Karwin (bkarwin) on 2006-11-13T15:15:30.000+0000

Changing fix version to 0.8.0.

Posted by Bill Karwin (bkarwin) on 2006-12-29T14:35:40.000+0000

The problem is that the generated SQL may include ambiguous references to columns of the same name in more than one table.

The solution is to prefix the table name or correlation name to the columns, so that columns for a given table, or a wildcard "*" for all columns from the table, are retrieved specifically from one table.

The implementation given is not general-purpose:

  • The backticks `` are MySQL-specific identifier delimiters. The Db adapter should provide the correct quoting for identifiers. See ZF-1.
  • Inferring cases from the "*" or "(" characters does not account for special characters that may occur within delimited identifiers. That is, "foo(bar" is a legitimate identifier when delimited.

Posted by Bill Karwin (bkarwin) on 2007-01-05T17:02:21.000+0000

Recategorize in Zend_Db_Select component.

Posted by Bill Karwin (bkarwin) on 2007-02-08T20:41:15.000+0000

Fixed in revision 3320.

Now columns in the select-list are prepended by the correlation name.

If you have columns that should not have correlation name prepended, use '' as the table name. For example:

<pre class="highlight">
$select->from( '', 'count(*)');

I may introduce a function columns() for this purpose too.

Have you found an issue?

See the Overview section for more details.


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

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