我编写了以下SQL查询:
$media_category_ids = array( 11, 12);
$params = array();
$sql = "SELECT `id`
FROM query
WHERE 1=1
AND WHERE query.media_category_id NOT IN (:media_category_ids)";
$params['media_category_ids'] = implode(",",$media_category_ids);
$prepared_query = $c->prepare($sql);
$prepared_query->execute($params);
但是我似乎无法在'NOT IN'子句中获得指定参数的语法,因为我收到以下错误:
Message: An exception occurred while executing 'SELECT `id` FROM query WHERE 1=1 AND WHERE query.media_category_id NOT IN (:media_category_ids)': SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE query.media_category_id NOT IN ('11,2')' at line 4
如果有人能指出我正确的方向,我真的很感激。
答案 0 :(得分:1)
在WHERE
运算符
AND
AND WHERE query.media_category_id
^here
答案 1 :(得分:0)
使用以下查询,不需要其他WHERE
:
SELECT `id`
FROM query
WHERE 1=1
AND query.media_category_id NOT IN (:media_category_ids)