我有一个函数可以检索用户信息并将其存储在类中的变量中:
public function UserInformation() {
$query = "SELECT * FROM users WHERE username = '$this->user'";
try {
$stmt = $this->db->prepare($query);
$stmt->execute();
}
catch(PDOException $ex)
{
die("Failed to run query: " . $ex->getMessage());
}
$rows = $stmt->fetch();
$email = $rows['email'];
$username = $rows['username'];
}
然后我将如何显示该函数中的单个变量?我试过echo $retrieveInfo->UserInformation->username;
没有成功,我该怎么做?