不太熟悉Symfony中的Doctrine::
查询,但我需要修改数据库查询。这是下面的原始代码:
function getUserById($userId) {
try {
return Doctrine :: getTable('UserDetails')->find($userId);
} catch (Exception $e) {
throw new DaoException($e->getMessage());
}
}
我想将另一个字段(状态)添加到查询的 where 子句。我试过了
return Doctrine :: getTable('UserDetails')->find($userId)->andWhere('status=1');
但它没有奏效。请问我该怎么办以及如何返回受 select 语句影响的行数。
带有静态方法的学说类似乎指的是 orm 框架的相同旧版本。
顺便说一句,您可以尝试通过传递 where 条件数组来调用findBy
。
在您的情况下,请尝试以下操作:
return Doctrine :: getTable('UserDetails')->findBy(array('userId' =>$userId, 'status' => 1));
希望这个帮助