I keep getting "Fatal error: Call to a member function prepare() on a non-object in /var/www/html/portal_core/build_portal.php on line 30". I am new to PDO and I'm really using this as a test to get my head around it. could you guys help me to understand what I am doing wrong ?
<?php
class build_portal
{
protected $dbh;
function __construct($dbname,$theme)
{
try
{
$dbh = new PDO('mysql:dbname='.$dbname.';host=localhost',"username","password");
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->log_error("Construct 1st Try statement 3rd Line");
}
catch (PDOException $e)
{
echo "Page Could Not Be Loaded";
return -1;
}
}
function log_error($cause)
{
try
{
$sth = $this->dbh->prepare("SELECT * from portal_errors");
$sth->setFetchMode(PDO::FETCH_ASSOC);
$sth->execute();
}
catch (PDOException $e)
{
print_r($e->errorInfo);
}
}
} ?>