1

I am trying to execute a nested query which is failing using mysqli::query method. The query works perfectly on mysql command prompt.

Here is the relevant piece of code:

$select_records = "SELECT c.creative_id
                        FROM creatives AS c
                        WHERE c.creative_id NOT
                        IN (
                            SELECT tr.creative_id
                            FROM  `term_relationships` AS tr
                            INNER JOIN  `terms` AS t ON t.term_id = tr.term_id
                            WHERE t.taxonomy =  'category'
                        )
                        ORDER BY c.creative_id ASC ";
$res = $this -> mysqli_connect -> query($select_records);

$res yields false

How to do this? Thanks.

hvs
  • 518
  • 1
  • 5
  • 21
  • Does this answer your question? [mysqli\_fetch\_assoc() expects parameter / Call to a member function bind\_param() errors. How to get the actual mysql error and fix it?](https://stackoverflow.com/questions/22662488/mysqli-fetch-assoc-expects-parameter-call-to-a-member-function-bind-param) – Dharman May 01 '20 at 15:59

2 Answers2

2

try testing in this way

$mysqli = new mysqli("my_host", "my_user", "my_password", "my_db");

$select_records = "SELECT c.creative_id
                    FROM creatives AS c
                    WHERE c.creative_id NOT
                    IN (
                        SELECT tr.creative_id
                        FROM  `term_relationships` AS tr
                        INNER JOIN  `terms` AS t ON t.term_id = tr.term_id
                        WHERE t.taxonomy =  'category'
                    )
                    ORDER BY c.creative_id ASC ";

if ($result = $mysqli->query($select_record)) {
  printf("Select returned %d rows.\n", $result->num_rows);
} else {
  printf("Problem with Query");
}
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
0

I made a stupid error. I was connecting to a different database than the one I intended. Hence the error. Sorry for the trouble.

hvs
  • 518
  • 1
  • 5
  • 21