加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – zend不使用列,并选择一切

发布时间:2020-12-13 18:08:01 所属栏目:PHP教程 来源:网络整理
导读:我有以下代码 $result = $handle-select()-from('store_details') -where('store_details.store_id=?',$id) -columns('store_details.store_name'); //-query(ZEND_DB::FETCH_OBJ); 但是,当我运行它时,选择整行,而不仅仅是我想要的列. 这是__toString的输出
我有以下代码
$result = $handle->select()->from('store_details')
                               ->where('store_details.store_id=?',$id)
                               ->columns('store_details.store_name');
                               //->query(ZEND_DB::FETCH_OBJ);

但是,当我运行它时,选择整行,而不仅仅是我想要的列.
这是__toString的输出

SELECT `store_details`.*,`store_details`.`store_name` 
FROM `store_details` WHERE (store_details.store_id=8)

有帮助吗?

columns()方法用于向现有的from或join添加列.构建查询的正确方法是:
$result = $handle->select()->from('store_details','store_details.store_name')->where('store_details.store_id=?',$id);

您需要将所需的列指定为from()方法的第二个参数,如果它只是一个列,则指定为字符串,或者指定为多个列的数组.从Zend_Db_Select docs

In the second argument of the from()
method,you can specify the columns to
select from the respective table. If
you specify no columns,the default is
“*”,the SQL wildcard for “all
columns”.

You can list the columns in a simple array of strings,or as an associative mapping of column alias to column name. If you only have one column to query,and you don’t need to specify a column alias,you can list it as a plain string instead of an array.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读