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

旧城冷巷雨未停 提交于 2019-12-06 19:31:31

问题


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


回答1:


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'));



回答2:


$select->from(
    array('sh'=>'shopping'),
    array('shopping_id','shopping_details','friend'=>'type', 'alias'=>'column or expression')
);


来源:https://stackoverflow.com/questions/3305470/zend-db-selecting-constants-columns-that-do-not-exist-in-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!