Search code examples
phpmysqliprepared-statement

Fatal error: Call to a member function fetch_assoc() on a non-object php mysql prepared statement


I have the following prepared statement for select query

$product_info = $this->mysqliengine->prepare("select product_id, sku from product limit 10");
        $product_info->execute();
        $res = $product_info->bind_result();
        while($row = $res->fetch_assoc()) {
            echo $row['sku'].'<br />';
        }

But It is showing fatal error as

Fatal error: Call to a member function fetch_assoc() on a non-object


Solution

  • try to debug yourself

    I hope this will solve

    $product_info = $this->mysqliengine->prepare("select product_id, sku from product limit 10");
            $product_info->execute();
            $product_info->bind_result($product_id,$sku);
    
            while($product_info->fetch()) {
                echo $product_id.'<br />';
            }
            $product_info->close();