开发者

Why am I getting: Call to a member function fetch_assoc() on a non-object for this recursive function?

Can anyone tell me I get the error: Fatal error: Call to a member function fetch_assoc() on a non-object for this method inside the class

This is a recursive function, and it runs fine the first time, is the second time when I get the error.

    function getSite($var, $var1 = 开发者_JS百科0, $numLevel = 1){
  //get the page
  $qry = "SELECT * FROM table WHERE columnA = $var AND columnB = $var1 ORDER BY parent, position ASC";

  $arrPage = $this->my_sqli->query($qry);

  //a valid resut was returned from the DB
  while($obj =  $arrPage->fetch_assoc()){
   //add to array
   if($obj['id']){
    $this->arrMenu = array(
     'id' => $obj['id'],
     'parent' => $obj['parent'],
     'level' => $numLevel
    );

             ... some more code 

              // call the function again
              getSite($value1);
             }
        }
   }


You are not including error checking.

Change

$arrPage = $this->my_sqli->query($qry);

to

if ( ($arrPage = $this->my_sqli->query($qry)) === false) {
        printf("Error: %s in query %s\n", $this->my_sqli->error,$qry);
    }


Normally when i see those errors there's something wrong with the query, try echo the query and executing it in something like Query Browser

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜