SQL错误:返回值是布尔值?

时间:2017-03-05 20:20:29

标签: php mysql sql mysqli

我之前已经使用了mysqli$database->query(...);fetch_assoc()函数,但这一次,我很困惑......

我的PHP总是告诉我:

  

PHP致命错误:未捕获错误:在/var/www/vhosts/httpdocs/afterUpdate.php:24中调用null上的成员函数fetch_assoc()

这是我的代码:

if($database->connect_errno){
$myfile = fopen("httpdocs/wp_all_import.txt", "w");
fwrite($myfile, "+++ After Update +++\n+++Couldn't connect to database!+++\n\n");
fclose($myfile);
}

$values = $database->query("SELECT `ID` FROM `fWR6qIN_posts` where post_type = product AND post_status = publish");

$k = 0;
$count_values = mysqli_num_rows($values);
$myfile = fopen("httpdocs/wp_all_import.txt", "w");
fwrite($myfile, $count_values . "\n");
fclose($myfile);

while($row = $values->fetch_assoc()){
    if($row["ID"] != null){
        $k = $k + 1;
    }
}

但到底哪里出错? - 我的其他PHP文件看起来完全一样吗?

我在mysqli_num_rowsfetch_assoc()出现此错误。但通常我应该返回2039个ID ??

我没有收到数据库错误! - 建立连接!

问候,谢谢!

1 个答案:

答案 0 :(得分:1)

可能是你错过报价

  $values = $database->query("SELECT `ID` 
            FROM `fWR6qIN_posts` where post_type = 'product' AND post_status = 'publish'");