yii2 这条sql查询语句,查询应该怎么写

请问这条sql语句:select count(*) from token where 'user_id'=$tokenInfo['user_id'] and create_time > $tokenInfo['create_time'];
用yii2框架的查询方法,应该怎么写?我像下面这样写是错误的:

$newCount = Token::find()->where(
[

'user_id' => $tokenInfo['user_id'],
['>', 'create_time', $tokenInfo['create_time']]

])->count();

请知道的指教下我,先谢谢了!!!

阅读 5.6k
1 个回答
$newCount = Token::find()->where(
    ['user_id' => $tokenInfo['user_id']])->andWhere([
    ['>', 'create_time', $tokenInfo['create_time']]
    ])->count();

或者

User::find()->where(['and', ['xxx' => 0, 'yyy' => 2], ['>', 'zzz', $time]);

更多参考 http://www.getyii.com/topic/47

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进