Reputation: 3
I get this error: Call to a member function prepare() on a non-object in
require("gebruikersdata.php");
class Database
{
private $con;
public function _construct($host,$username,$password,$database)
{
$this->con = new PDO("mysql:host=".$host.";dbname=".$database,$username,$password);
}
public function getGebruiker($sql)
{
$statement = $this->con->prepare($sql);
$statement->execute();
while($row = $statement->fetch())
{
$dataSet[] = new GebruikersData ($row);
}
if (!empty($dataSet))
return $dataSet;
else
return null;
}
}
What am I doing wrong? Thank you in advance!
Upvotes: 0
Views: 63
Reputation: 2456
You probably need to change _construct()
to __construct()
(note the double underscores).
Otherwise it won't be called on class initialization.
Upvotes: 1