I'm receiving this error, I know there are multiple topics about this already but I couldn't find a proper solution for mine.
Uncaught Error: Call to a member function prepare() on null in C:\xampp\htdocs\ELO-Alfa\dev\app\helpers\db.inc.php:28
line 28:
public function query($sql, $array = []){
$this->dbQuery = $this->dbConnect->prepare($sql);
$this->dbQuery->execute($array);
}
This is the function that calls the query
public function getDay(){
global $db;
$db->query('SELECT * FROM day');
$day = $db->getAll();
foreach($day as $days):?>
<th><?= $days['day_name'] ?></th>
<?php endforeach;
}
And this the echo
<?= $agenda->getDay();?>
connection
public function connection(){
try{
$this->dbConnect = new PDO('mysql:host:' . $this->dbHost . ';dbname:' . $this->dbName,
$this->dbUser,
$this->dbPass);
}catch(PDOException $e){
echo 'Connection error: ' . $e->getMessage();
return false;
}
return true;
}
```