在PDO的预成对语句中,请求使用> 1,这段代码做错了什么。

时间:2022-04-17 20:50:12

My code is...

我的代码是……

$select_product_dups = $db->prepare("SELECT products_model FROM products GROUP BY products_model HAVING count( products_model ) > 1");

My editor is barking at me (at least highlighting with little info), so I figured I will check with the community on this. Everything looks to be good otherwise.

我的编辑在对着我狂叫(至少是用很少的信息来强调),所以我想我要和社区联系一下。否则一切看起来都很好。

Full statement...

完整的声明……

$select_product_dups = $db->prepare("SELECT products_model FROM products GROUP BY products_model HAVING count( products_model ) > 1");
$select_product_dups->setFetchMode(PDO::FETCH_ASSOC);
$select_product_dups->execute();
while ($select_product_dups_row = $select_product_dups->fetch()){
    $dups[] = $select_product_dups_row['products_model'];
}

1 个解决方案

#1


2  

Your query looks legit to me.

你的询问对我来说是合法的。

No idea why your editor might be complaining, but the message you report, "No data sources are configured to run this SQL", doesn't seem related to the particulars of your statement. Have you tried replacing your query with something trivial, like SELECT products_model FROM products LIMIT 1? My guess is that you'll still get the warning.

不知道为什么编辑器可能会抱怨,但是您报告的消息“没有配置为运行SQL的数据源”,这似乎与您的声明的细节无关。您是否尝试过用一些无关紧要的东西替换您的查询,比如从产品限制1中选择products_model ?我猜你还是会得到警告的。

Anyway, editor warnings are just eyeballing it; your SQL engine is the true judge of any query.

无论如何,编辑警告只是目测;您的SQL引擎是对任何查询的真正判断。

Edit: So the warning is indeed unrelated to the content of the query. My guess is that the editor can't see where you initialize the database connection (a "data source" is a database connection). Obviously it works, so I'd just ignore the warning and move on to getting the query to give you exactly what you want.

编辑:所以警告实际上与查询的内容无关。我的猜测是编辑器无法看到您初始化数据库连接的地方(一个“数据源”是一个数据库连接)。显然它是有效的,所以我忽略了警告,然后继续进行查询,以得到您想要的结果。

#1


2  

Your query looks legit to me.

你的询问对我来说是合法的。

No idea why your editor might be complaining, but the message you report, "No data sources are configured to run this SQL", doesn't seem related to the particulars of your statement. Have you tried replacing your query with something trivial, like SELECT products_model FROM products LIMIT 1? My guess is that you'll still get the warning.

不知道为什么编辑器可能会抱怨,但是您报告的消息“没有配置为运行SQL的数据源”,这似乎与您的声明的细节无关。您是否尝试过用一些无关紧要的东西替换您的查询,比如从产品限制1中选择products_model ?我猜你还是会得到警告的。

Anyway, editor warnings are just eyeballing it; your SQL engine is the true judge of any query.

无论如何,编辑警告只是目测;您的SQL引擎是对任何查询的真正判断。

Edit: So the warning is indeed unrelated to the content of the query. My guess is that the editor can't see where you initialize the database connection (a "data source" is a database connection). Obviously it works, so I'd just ignore the warning and move on to getting the query to give you exactly what you want.

编辑:所以警告实际上与查询的内容无关。我的猜测是编辑器无法看到您初始化数据库连接的地方(一个“数据源”是一个数据库连接)。显然它是有效的,所以我忽略了警告,然后继续进行查询,以得到您想要的结果。