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.

1

2 Answers 2

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");
}
Sign up to request clarification or add additional context in comments.

1 Comment

And if you want to know what's actually wrong use printf("Problem with SQL Query: %s", $mysqli->error);.
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.