I got the error showing above. I have looked on this website, but I can't find the right fix to solve my problem.
I am trying to write a User-class. The following code is my code so far.
class User
{
private $_id;
public function __construct($id)
{
$this->_id = $id;
}
public function getUsername()
{
global $db;
$query = $db->prepare("SELECT * FROM users WHERE id = ?");
$query->bindValue(1, $this->_id);
$query->execute();
}
}
The result is the following error and I don't know how to fix this...
Fatal error: Call to a member function bindValue() on a non-object in
Edit:
Here is how I am using it:
$user = new User($_SESSION['logged_in']);
$username = $user->getUsername();
Sidenote: session_start();
is loaded.