Selecting arbitrary strings with Zend DB Select?

Posted by wizzard on Stack Overflow See other posts from Stack Overflow or by wizzard
Published on 2010-05-03T23:18:15Z Indexed on 2010/05/03 23:28 UTC
Read the original article Hit count: 425

Filed under:
|

I am using the fluent interface to create a Zend DB Select object/query. As part of the query, I would like to select an arbitrary string, like "SELECT 'foo' AS 'type' FROM ...". foo is not a column, it's just a string literal.

When I select an arbitrary number, the query works as expected. When I change it to a string, Zend tries to treat foo as a column, and throws an error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'l.foo' in 'field list'

I have tried wrapping the string in Zend_Db_Expr in various ways such as:

$select->columns(array('type' => new Zend_Db_Expr('foo')));

That stops Zend from adding the correlation name, but it still treats it as a column:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'foo' in 'field list'

I feel like I must be missing something obvious here. How do I tell Zend to stop treating this as a column?

© Stack Overflow or respective owner

Related posts about zend-framework

Related posts about zend-db