mysqli - fetch_Array error call to a member function fetch_array() on a non-object mysqli

55,133

Solution 1

This answer has been written very long time ago and become irrelevant.

Since then I learned the proper solution for this problem and wrote it in this answer. Please navigate there.

Solution 2

The query probably failed and mysqli::query returned FALSE. Therefore $runGetChartData is not a mysqli_result object, but a boolean, which is why you are getting your error.

From the documentation:

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.

Share:
55,133
Vignesh Gopalakrishnan
Author by

Vignesh Gopalakrishnan

Fond of learning and exploring open source languages.

Updated on August 08, 2020

Comments

  • Vignesh Gopalakrishnan
    Vignesh Gopalakrishnan almost 4 years

    I am new to mysqli and started trying to learn basic things. With respect to this i example (http://php.net/manual/en/mysqli-result.fetch-array.php) i was trying fetch_array. Here is my code.

    $sqlGetChartData    =   "SELECT date, ratepersqft, location 
                              FROM ratepersqft
                             WHERE project_id = 1";
    $runGetChartData    =   $mysqli->query($sqlGetChartData);
    
    while($rowGetChartData = $runGetChartData->fetch_array(MYSQLI_BOTH))
        $arrGetChartData[]  =   $rowGetChartData;
    
        print "<pre>";
        print_r($arrGetChartData);
        exit();
    

    Here i am getting this error Call to a member function fetch_array() on a non-object on line next to while condition line. I tried googling it and did not get result for my problem. Hope my question is clear. Thanks in Advance.

  • Hanky Panky
    Hanky Panky over 11 years
    That was such a nice way of explaining this, +1.
  • Dharman
    Dharman almost 4 years
    Don't you think this answer could use some retouch? I don't agree with the solution proposed. Maybe we should close it as a duplicate of stackoverflow.com/a/22662582
  • Your Common Sense
    Your Common Sense almost 4 years
    As you know, closing as a dupe doesn't really change anything, but I'll try t do something.