$where = '';
if(!empty($filter_time)) $where =" and date_created > now()-Interval <b>$filter_time </b> minute ";
if(!empty($filter_category))
$where.= "and path LIKE '<b>$filter_category</b>%' ";
$sql = Yii::$app->db->createCommand("SELECT COUNT(*) FROM Pages
JOIN categories ON categories = id_categories WHERE status = 1 $where")->queryScalar();
bindValues()
. $where = '';
if(!empty($filter_time)) $where =" and date_created > now()-Interval :filter_time minute ";
if(!empty($filter_category))
$where.= "and path LIKE ':filter_category%' ";
$sql = Yii::$app->db->createCommand("SELECT COUNT(*) FROM Pages
JOIN categories ON categories = id_categories WHERE status = 1 $where")
->bindValue(':filter_time', $filter_time)
->bindValue(':filter_category', $filter_category)
->queryScalar();
$query = new \yii\db\Query();
$query->from('Pages')
->leftJoin('categories', ['categories' => 'id_categories'])
->where(['status' => 1])
->andFilterWhere(['like', 'path', $filter_category]);
if (! empty($filter_time)) {
$expression = new \yii\db\Expression('now() - interval :filter_time minute', [
':filter_time' => $filter_time
]);
$query->andWhere(['>', 'date_created', $expression]);
}
Есть такой код
SELECT COUNT(*) FROM Pages
Как, правильно прописать bindValues().
$post = Yii::$app->db->createCommand('SELECT * FROM post WHERE id=:id AND status=:status')
->bindValue(':id', $_GET['id'])
->bindValue(':status', 1)
->queryOne();