简体   繁体   English

出现索引问题时,查询/准备语句中未使用索引

[英]No index used in query/prepared statement, when there is an index issue

I am trying to perform a query and am getting the following error.. 我正在尝试执行查询,并收到以下错误。

7Error: No index used in query/prepared statement SELECT `id`, `category_id`, `topic_id`, `post_creator`, `post_content`, `post_date` FROM forum_posts WHERE `category_id`=? AND `topic_id`=?

I originally had this line of code for it... 我最初有这行代码...

if($stmt2 = $con->prepare("SELECT * FROM forum_posts WHERE `category_id`=? AND `topic_id`=?")) {

So I tried changing it to the following to give it an index. 因此,我尝试将其更改为以下内容以为其提供索引。

if($stmt2 = $con->prepare("SELECT `id`, `category_id`, `topic_id`, `post_creator`, `post_content`, `post_date` FROM forum_posts WHERE `category_id`=? AND `topic_id`=?")) {

Why would this error be occuring? 为什么会出现此错误? I have php error reporting on. 我有php错误报告。

error_reporting(E_ALL);
ini_set('display_errors', 1);

However, even when I comment it out, the error still occurs and it kills my code. 但是,即使我将其注释掉,该错误仍然会发生,并且会杀死我的代码。 Anyone know why this error is coming up and how I can fix it? 任何人都知道为什么会出现此错误,我该如何解决?

According to the answer provided here : 根据此处提供的答案:

mysqli_report(MYSQLI_REPORT_ALL ^ MYSQLI_REPORT_INDEX); mysqli_report(MYSQLI_REPORT_ALL ^ MYSQLI_REPORT_INDEX);

Turns off "Report if no index or bad index was used in a query" yet keeps other reporting on. 关闭“如果查询中未使用索引或错误索引,则报告”,但保持其他报告状态不变。

By using 'E_ALL', you are enabling the reporting of this error/warning. 通过使用“ E_ALL”,可以启用此错误/警告的报告。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM