11

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 Answer 1

12

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.