致命错误:在布尔值上调用成员函数fetch_array() [英] Fatal error: call to a member function fetch_array() on boolean

查看:373
本文介绍了致命错误:在布尔值上调用成员函数fetch_array()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试执行我的php脚本时,出现致命错误:在boolean in上调用成员函数fetch_array()"错误.有问题的代码在这里:

I am getting the "Fatal error: call to a member function fetch_array() on boolean in..." error when trying to execute my php script. The code in question is here:

function backup()
{
    global $mysqli;

    $bup        = "SELECT p.product_id, p.ean, p.image, p.model,  p.status, p.price_sync, p.modified_by, p.date_modified, pd.name, pd.description, pd.language_id, pd.meta_description, pd.meta_keyword, pd.tag FROM oc_product p INNER JOIN oc_product_description pd ON p.product_id = pd.product_id";
    $backup     = $mysqli->query($bup);
    $megainsert = "REPLACE INTO oc_product_backup(product_id, ean, image, model,  status, price_sync, modified_by, date_modified, name, description, language_id, meta_description, meta_keyword, tag) VALUES ";

    while($row  = $backup->fetch_array(MYSQLI_ASSOC))
    {
        $product_id       = $mysqli->real_escape_string($row['product_id']);
        $ean              = $mysqli->real_escape_string($row['ean']);
        $image            = $mysqli->real_escape_string($row['image']);
        $model            = $mysqli->real_escape_string($row['model']);
        $name             = $mysqli->real_escape_string($row['name']);
        $description      = $mysqli->real_escape_string($row['description']);
        $meta_description = $mysqli->real_escape_string($row['meta_description']);
        $meta_keyword     = $mysqli->real_escape_string($row['meta_keyword']);
        $tag              = $mysqli->real_escape_string($row['tag']);

        $megainsert      .= "('".$product_id."', '".$ean."', '".$image."', '".$model."',  '".$row['status']."', '".$row['price_sync']."', '".$row['modified_by']."', '".$row['date_modified']."', '".$name."', '".$description."', '".$row['language_id']."', '".$meta_description."', '".$meta_keyword."', '".$tag."'),";
    }

    $backup->close();
    $megainsert = substr_replace($megainsert, "", -1);
    $dobackup   = $mysqli->query($megainsert);
    if(!$dobackup) return $mysqli->error;
    else return true;
}

问题所在的是以下几行:

the following line is where the problem is:

while($row  = $backup->fetch_array(MYSQLI_ASSOC))

上面的函数之前的代码如下:

The code right before the function above is as follows:

   function clearBackupPrices()
{
    global $mysqli;

    $clean   = "TRUNCATE TABLE oc_product_price_backup";
    $doclean = $mysqli->query($clean);
    if(!$doclean) return $mysqli->error;
    else return true;
}

我研究并调查了相同问题的其他答案,但没有运气解决.请问有人对我的问题有什么建议吗?谢谢大家.

I researched and looked into other answers with the same question, but had no luck resolving it. Does anyone have a suggestion for my problem, please? Thank you all in advance.

推荐答案

来自 php文档,MySQLi :: query()将:

From the php documentation, MySQLi::query() will:

失败时返回FALSE.要成功执行SELECT,SHOW,DESCRIBE或 EXPLAIN查询mysqli_query()将返回mysqli_result对象.为了 其他成功的查询mysqli_query()将返回TRUE.

Returns FALSE on failure. For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a mysqli_result object. For other successful queries mysqli_query() will return TRUE.

这意味着以下查询失败(并因此生成了$backup = FALSE而不是一个解释您的错误声明的对象):

This means that the following query is failing (and hence making $backup = FALSE rather than an object which explains your error statement):

$mysqli->query($bup);

这又意味着sql语句$bup导致错误.我建议您检查一下它和您的桌子.看来该错误不是语法错误(因为语法错误会导致更早的错误消息),这意味着MySQL可以读取您的语句,但是由于某种原因该操作失败.您将必须检查您的SQL语句以及表,看看逻辑上的缺陷是什么.

Which in turn means that the sql statement $bup is causing an error. I recommend reviewing it and your table. It seems the error is not a syntax error (since a syntax error would have caused an even earlier error message), which means that MySQL can read your statement, but the operation is failing for some reason. You'll have to review your SQL statement as well as your table and see what the flaw in the logic is.

这篇关于致命错误:在布尔值上调用成员函数fetch_array()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆