php - zend 不使用列,并选择所有内容

标签 php zend-framework zend-db

我有以下代码

$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() 方法用于添加 列到现有的fromjoin。构建查询的正确方法是:

$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.

关于php - zend 不使用列,并选择所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1023789/

相关文章:

php - 使用 Authorize.NET PHP SDK 的 SSL 选项无效

php - 使用 PHP 的横幅统计和 Google Analytics

php - 类似 Rails 的 PHP 控制台?

php - Zend Framework 2 返回对象作为查询结果

javascript - highcharts 系列选项的问题

php - 在 Zend 中查询类似 "ON DUPLICATE KEY UPDATE"

mysql - 多选择的Sql(zend db select)

php - Zend Framework 错误 [数据库连接]

javascript - Php/Jquery/Ajax : On Accordian Click, 它在 Accordion 内的页面中加载内容

php - 在共享 cPanel 服务器上托管 PHP Zend Framework 应用程序