$query_ol = Orderlist::find()->where([
'status' => Orderlist::STATUS_ACTIVE,
'phone' => \Yii::$app->user->identity->username,
]);
$query_ol->andWhere(['<', 'addtime', time()]);
$query_ol->andWhere(['>=', 'addtime', ':addtime1']);
if($query_ol->andWhere([':addtime1'=>strtotime("-1 month")])->count()>=4){
echo 'hello';
}
报错提示如下:
Database Exception – yii\db\Exception
SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
The SQL being executed was: SELECT COUNT(*) FROM so_orderlist
WHERE (((status
=’1′) AND (phone
=’18663697137′)) AND (addtime
< 1493111483)) AND (addtime
>= ‘:addtime1’)
Error Info: Array
(
[0] => HY093
[1] => 0
)
你打印过最后执行的sql吗 看看是否你那个占位符到底是否好用了
多加一句,我记得andwhere是可以加params, 可以用下面2种方法,简化一行代码。
$query_ol->andWhere(‘addtime>=:addtime1’, [‘:addtime1’=>strtotime(“-1 month”)]);
$query_ol->andWhere([‘>=’, ‘addtime’, strtotime(“-1 month”)]);