I am trying to execute a database query but I am getting this error. I am very frustrated.
class Database {
//verbind met onze database
private $host = DB_HOST; //server naam - normaal localhost
private $dbName = DB_NAME; // Naam van de database
private $username = DB_USER; //Pas aan als dit nodig is
private $password = DB_PASS; //In xamppp is dit normaal leeg maar pas aan als dit nodig is.
private $pdo;
public $lastInsertId;
function __construct() {
$this->startConnection();
}
function startConnection() {
$this->pdo = new PDO("mysql:host=".$this->host.";dbname=".$this->dbName,$this->username,$this->password); //Gebruik de variables die we eerder hebben ge-set
}
public function endConnection(){
$this->pdo = null;
}
public function query($query, $params = array()) {
$statement = $this->pdo->prepare($query);
$statement->execute($params);
if (explode(' ', $query)[0] == 'SELECT') {
$data = $statement->fetchAll();
return $data;
}
}
public function lastID($query, $params = array()){
$stmt = $this->pdo->prepare($query);
$stmt->execute($params);
$ID = $this->pdo->lastInsertId();
$this->lastInsertId = $this->pdo->lastInsertId();
return $ID;
}
This is my database class. I of course handle my database stuff here
This is where I get my error from, this is from another page and it says: Fatal error: Uncaught Error: Non-static method Database::query() cannot be called statically in C:xampphtdocsExcellentTasteviewsReservations.php:7 Stack trace: #0
$reservations = Database::query("SELECT * from reserveringen");