Home  >  Q&A  >  body text

Why does an error appear when accessing fetch?

// Get a single query result

public static function fetch($sql){

return $this->conn->query($sql)->fetch( PDO::FETCH_ASSOC);

}

Error:

Fatal error: Using $this when not in object context in D:\Web\api\Db.php on line 79

RiVolRiVol2443 days ago1639

reply all(4)I'll reply

  • 寻觅 beyond

    寻觅 beyond2018-03-07 11:42:21

    Check it, it should be that there are a few more curly braces in front of this method, causing your fetch to be defined outside the class, so this situation occurs

    reply
    0
  • phpcn_u58808

    phpcn_u588082018-03-06 17:12:01

    111111111111

    reply
    1
  • 炎

    2018-03-06 10:33:59

    Can I take a screenshot of the entire page of code?

    reply
    0
  • 辉

    2018-03-05 21:27:12

    Fatal error, there is no such object in the $this context, view the content of the variable

    reply
    0
  • RiVol

    According to the writing method in the video, why is an error reported?

    RiVol · 2018-03-05 21:28:31
  • Cancelreply