在symfony中使用doctrine检索数据和行计数

时间:2014-11-30 13:14:29

标签: php symfony doctrine-orm doctrine

我不太熟悉Symfony中的Doctrine::查询,但我需要修改数据库查询。这是下面的原始代码:

function getUserById($userId) {
     try {
        return Doctrine :: getTable('UserDetails')->find($userId);
    } catch (Exception $e) {
        throw new DaoException($e->getMessage());
    }
}

我想在查询的where子句中添加另一个字段(status)。我试过了

return Doctrine :: getTable('UserDetails')->find($userId)->andWhere('status=1');

但它没有用。 请问我该怎么做以及如何返回受select语句影响的行数。

1 个答案:

答案 0 :(得分:1)

使用静态方法的doctrine类似乎引用了同一个旧版本的orm框架。

BTW您可以尝试调用findBy传递where where数组的数组。

在你的情况下试试这个:

return Doctrine :: getTable('UserDetails')->findBy(array('userId' =>$userId, 'status' => 1));

希望这个帮助