Attempted method call: undefined function error

I have a class to connect to my database, cut stuff and return things from a db request. Anyway, the problem I am facing is that I try to call the runQuery() method, but every time I try, I get this error:

Fatal error: call to undefined runQuery () function in DatabaseConnector.php line 22

Any ideas maybe? I know that runQuery is private, but it is within the same class. Just for the blows, I changed it in public, and still got the same error :(
 final class DatabaseConnector { private $db; public function DatabaseConnector() { // constructor } public function connectMySQL($host, $user, $passwrd, $db, $query) { @ $db = new mysqli($host, $user, $passwrd, $db); if (mysqli_connect_errno()) { return mysqli_connect_errno(); } else { $queryResult = runQuery($query); return $queryResult; } } private function runQuery($query) { $result = $db->query($query); return $result; } } 
+4
source share
1 answer

In PHP, you need a prefix of the methods / variables of the $this object level, otherwise it will look for a function / variable in the global namespace.

So change $queryResult = runQuery($query); on $queryResult = $this->runQuery($query);

+14
source

All Articles