我犯了一个愚蠢的错误。我连接到的数据库与我想要的数据库不同。因此出现了错误。很抱歉给你添麻烦。
我正在尝试执行一个嵌套查询,但使用mysqli::query方法失败。查询在mysql命令提示符下运行良好。
以下是相关代码:
$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产生虚假
如何做到这一点?谢谢
尝试以这种方式测试
$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");
}