There is such a piece of code:

class tapinambur { protected $mysqli = false; protected $db_name = ''; function __construct($db_name) { $this->db_name = $db_name; } public function connectDB () { $this->mysqli = new mysqli('localhost', '***', '***', $this->db_name); $this->mysqli->query("SET NAMES 'utf8'"); } public function closeDB () { $this->mysqli->close(); } function getNews() { connectDB(); $result = $this->mysqli->query("SELECT * FROM `news` ORDER BY `id` DESC"); closeDB(); return resultToArray($result); } 

When accessing getNews() says:

Call to undefined function connectDB ()

Help please, just started learning OOP in PHP .

PHP version: 7

    1 answer 1

    In a class, the call to your function must be done via $this i.e. $this->connectDB(); The same goes for the closeDB() method.


    Read more HERE