【问题标题】:Fetching Data From Prepared Statment In MySQLi And PHP从 MySQLi 和 PHP 中的准备好的语句中获取数据
【发布时间】:2014-06-25 13:29:25
【问题描述】:

您好,我正在尝试从我在 PHP 类中编写的准备好的语句中获取数据,并且我已经尝试了很多,请帮助这里是类成员中的 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; } ?>

请帮助.. 谢谢

【问题讨论】:

    标签: php mysql oop mysqli


    【解决方案1】:

    您需要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']; } ?>
    

    【讨论】:

    • 他正在尝试访问 $firstname, $lastname 但他忘记将结果绑定到变量。我错过了什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-11
    • 1970-01-01
    • 1970-01-01
    • 2010-12-24
    • 1970-01-01
    • 2011-06-20
    • 1970-01-01
    相关资源
    最近更新 更多