您好,我正在尝试从我在PHP类中编写的准备好的语句中获取数据,并且我已经尝试了Alot,请提供帮助,这是类成员中的PHP函数

public function Check() {
    $email = $this->getEmail();
    $user = $this->getUsername();
    $check = "SELECT firstName,lastName FROM members WHERE Email = ? AND Username = ? AND isActive = '1' ";
    $stmt = $this->conn->prepare($check);
    $stmt->bind_param("ss", $email, $user);
    $stmt->execute();
    return $stmt->fetch();
}


我想通过包含该类并在其中创建一个对象来在另一个页面中获取数据。这是我的尝试

<?php
                    $member = new Members();
                    $email = $member->setEmail(strip_tags(htmlspecialchars(trim($_GET['e']))));
                    $user = $member->setUsername(strip_tags(htmlspecialchars(trim($_GET['u']))));
                    if ($member->Check()) { echo $firstname." ".$lastname; } ?>


请帮忙 ..
谢谢

最佳答案

您需要bind the result variables

$stmt->execute();
$stmt->bind_result($firstname, $lastname);
$stmt->fetch();
return array('firstname' => $firstname,'lastname' => $lastname);

$member = new Members();
$email = $member->setEmail(strip_tags(htmlspecialchars(trim($_GET['e']))));
$user = $member->setUsername(strip_tags(htmlspecialchars(trim($_GET['u']))));
$results = $member->Check();
if ($results) { echo $results['firstname']." ".$results['lastname']; } ?>

08-19 00:42