我有下表
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');
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();