views:

143

answers:

1

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?

+1  A: 

Did you perhaps try:

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

You need to actually have quotes around the 'foo' in the SQL as well.

gnarf
That was it. Thanks!
wizzard