gpt4 book ai didi

mysql - 如何在 MySQL 查询中为 NOT IN 子句指定命名参数值?

转载 作者:行者123 更新时间:2023-11-29 00:19:11 25 4
gpt4 key购买 nike

我编写了以下 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 

如果有人能指出正确的方向,我将不胜感激。

最佳答案

AND 运算符之后删除附加的 WHERE

AND WHERE query.media_category_id  
^here

关于mysql - 如何在 MySQL 查询中为 NOT IN 子句指定命名参数值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21757965/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com