You should access dbh
property from your $db
object to get a database handler in your User
class:
$db = new db;
$stmt = $db->dbh->prepare ("INSERT INTO users (name, email) VALUES (:name, :email)");
Or you can change database
class __constructor
:
public function __construct(){
return $this->conn();
}
And conn()
method :
public function conn(){
try {
$this->dbh = new PDO($this->dsn, $this->username, $this->password);
$this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
return $this->dbh;
} catch (PDOException $e) {
$error = new Errors();
echo $error->displayError($e);
}
}