[英]zend not using columns, and selecting everything
I have the following code 我有以下代码
$result = $handle->select()->from('store_details')
->where('store_details.store_id=?', $id)
->columns('store_details.store_name');
//->query(ZEND_DB::FETCH_OBJ);
However, when I run it, the entire row is selected, not just the column I wanted. 但是,当我运行它时,选择整行,而不仅仅是我想要的列。 Here is the output from __toString
这是__toString的输出
SELECT `store_details`.*, `store_details`.`store_name`
FROM `store_details` WHERE (store_details.store_id=8)
Any help? 有帮助吗?
The columns()
method is for adding columns to an existing from or join . columns()
方法用于将列添加到现有的from或join 。 The correct way to build your query is: 构建查询的正确方法是:
$result = $handle->select()->from('store_details','store_details.store_name')->where('store_details.store_id=?', $id);
You need to specify the columns you want as the second parameter to the from() method, as a string if it is just one column, or as an array for multiple columns. 您需要将所需的列指定为from()方法的第二个参数,如果它只是一个列,则指定为字符串,或者指定为多个列的数组。 From the
Zend_Db_Select docs
: 来自
Zend_Db_Select docs
:
In the second argument of the from() method, you can specify the columns to select from the respective table.
在from()方法的第二个参数中,您可以指定要从相应表中选择的列。 If you specify no columns, the default is "*", the SQL wildcard for "all columns".
如果未指定列,则默认为“*”,即“所有列”的SQL通配符。
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.
如果只有一列要查询,并且不需要指定列别名,则可以将其列为纯字符串而不是数组。
If you already have the select object (means the from()
was called before), you should use $select->reset(Zend_Db_Select::COLUMNS);
如果你已经有select对象(意思是之前调用了
from()
),你应该使用$select->reset(Zend_Db_Select::COLUMNS);
and then call columns()
as you do in the example. 然后像在示例中一样调用
columns()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.