I want to populate class with constructor using FETCH_INTO of PDO:
class user
{
private $db;
private $name;
function __construct($id)
{
$this->db = ...;
$q = $this->db->prepare("SELECT name FROM users WHERE id = ?");
$q->setFetchMode(PDO::FETCH_INTO, $this);
$q->execute(array($id));
echo $this->name;
}
}
This does not working. No error, just nothing. Script has no errors, FETCH_ASSOC works fine.
What is wrong with FETCH_INTO?