PHP-原则选择语句始终返回表的所有字段

我有下表

Test:
    tableName: test
    columns:
        test_id:
            name: test_id as id
            primary: true
            autoincrement: true
            type: integer
            notnull: true
        test_name:
            name: test_name as name
            type: string(255)
        test_title:
            name: test_title as title
            type: string(255)

和这个dql陈述

$dql = Doctrine_Query::create()->select('t.name')->from('Model_Test t');

生成以下sql ist

SELECT t.test_id AS t__test_id, t.test_name AS t__test_name FROM test t

但是在获取了学说的结果之后,即使没有选择,我也可以访问标题字段:

foreach ($results as $result) {
    foreach ($result as $filed => $value) {
        echo "$filed => $value <hr>"; // echoes 'title' => null but title in db has other value
    }                                
}                                

也通过Zend_Debug :: dump($results-> toArray())进行转储;向我显示所有字段,好像我会选择一个*

那么如何限制返回的字段以匹配我的选择?

提前致谢

马丁

解决方法:

我猜:

因为

$results = $dql->execute();

将结果作为对象获取,未选择的变量用空值填充

$results = $dql->fetchArray(); 

获取一个数组,在这种情况下,仅显示选定的字段(除主键外)

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...