How do I use PDO FetchObject results with the $this variable?
Have a page class which is used to display a page that has its details stored in a database. Each page has a title and a description specific to that page. In production, there are many more variables and functions than those shown here.
class Page
{
var $title;
var $description;
function load_page()
{
$this->get_page_meta();
// do some more stuff and then
// send $this variable to template view that displays page
}
function get_page_meta()
{
$stmt = $dbh->query("SELECT title, description FROM pages WHERE page_id = '1'");
$stmt->fetch(PDO::FETCH_OBJ);
// HOW DO I MAKE THE RESULT SET REFERENTIAL USING $this?
// I want $this->title to be accessible
// without assigning $this->title = $result->title
}
}