1

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.

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?

1 Answers1

2

According to the answer provided here:

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.

Community
  • 1
  • 1
Tony
  • 124
  • 4
  • When I do this I get this error..`7Error: Commands out of sync; you can't run this command now` for `$driver = new mysqli_driver(); $driver->report_mode = MYSQLI_REPORT_ALL^MYSQLI_REPORT_INDEX;` –  Jul 23 '15 at 02:51
  • There is a pretty thorough answer to the 'out of sync' issue at http://stackoverflow.com/a/614741/5146041 – Tony Jul 23 '15 at 02:59