So I have a Database class with a function like this:
public function sql($sql) {
$result = $this->connection->query($sql);
return $result;
}
But it returns the error:
Fatal error: Uncaught Error: Using $this when not in object context
But I don't get it why I get this error, I've looked al around the internet, but nobody seems to have this exact problem.
This is my full database class:
namespace Core;
require_once ("../config.php");
class DB {
public $connection;
public function __construct() {
$this->connection();
}
public function connection() {
$this->connection = new \mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if ($this->connection->connect_error) {
die("Database fout");
}
}
public function sql($sql) {
$result = $this->connection->query($sql);
return $result;
}
}
Then I call it like so:
DB::sql('SELECT * FROM `users`');
But then I get the error. :/