Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend DB Selecting constants - columns that do not exist in table

I'm trying to do this query using Zend DB select but I'm not able to do so

This is the sql query

select shopping_id,shopping_details,"friend" as type
from shopping

Notice here how I'm specifying "friend" as type and friend is not a column in the shopping table.

Now how do I do this in Zend. I have tried this but it gives me an error saying "sh.friend Column does not exist"

$select->from(array('sh'=>'shopping'),array('shopping_id','shopping_details','"friend" as type');

Any help will be appreciated thanks

like image 979
Gublooo Avatar asked Jul 22 '10 02:07

Gublooo


2 Answers

Try with Zend_Db_Expr, maybe something like:

$select->from(array('sh'=>'shopping'),
    array('shopping_id','shopping_details',
         new Zend_Db_Expr('"friend" as type'));
like image 196
robertbasic Avatar answered Oct 27 '22 23:10

robertbasic


$select->from(
    array('sh'=>'shopping'),
    array('shopping_id','shopping_details','friend'=>'type', 'alias'=>'column or expression')
);
like image 42
Ballsacian1 Avatar answered Oct 27 '22 23:10

Ballsacian1