我剛剛意識到,在symfony中,如果您沒有提到特定字段,則doctrine會返回大量垃圾數據,例如調試時間等。我們如何只用字段結果查詢所有的數據庫字段?例如:SELECT * FROM user WHERE username ='abc',那麼它將只返回用戶表中不包括那些垃圾數據的所有字段。Symfony2:如何使用doctrine選擇數據庫中的所有字段,而無需垃圾數據
$q = $this
->createQueryBuilder('u')
->where('u.username = :username')
->setParameter('username', $username)
->getQuery();
try {
// The Query::getSingleResult() method throws an exception
// if there is no record matching the criteria.
$user = $q->getSingleResult();
var_dump($user);
} catch (NoResultException $e) {
$user = false;
}
上面的代碼的結果:
我並不需要所有這些數據,我只需要在數據的字段。非常感激你的幫助。謝謝。
謝謝你,這是我想要的。抱歉在問題中不清楚,我在這裏提到的垃圾是我不想要的數據。 – overshadow 2015-04-06 00:01:52