简体   繁体   English

带有fetch_assoc()的未定义方法mysqli_stmt :: get_result()

[英]Undefined method mysqli_stmt::get_result() with fetch_assoc()

I am working on a login and register android project. 我正在登录并注册android项目。 I tried different solutions for this PHP error, but none of them helped me. 我针对此PHP错误尝试了不同的解决方案,但没有一个对我有帮助。

I'm getting this error: 我收到此错误:

Call to undefined method mysqli_stmt::get_result() in ... on line 59 在第59行的...中调用未定义的方法mysqli_stmt :: get_result()

And line 59 is: $user = $stmt->get_result()->fetch_assoc(); 第59行是: $user = $stmt->get_result()->fetch_assoc();

I read that if I don't have drivers I should use bind & fetch instead, but I couldn't figure out how. 我读到,如果没有驱动程序,我应该改用bindfetch ,但是我不知道怎么做。

My function: 我的功能:

public function getUserByEmailAndPassword($email, $password) {

    $stmt = $this->conn->prepare("SELECT * FROM seemidavajaon WHERE email = ?");

    $stmt->bind_param("s", $email);

    if ($stmt->execute()) {
        $user = $stmt->get_result()->fetch_assoc();
        $stmt->close();
        return $user;
    } else {
        return NULL;
    }
}

After a day of messing with I finally got it right. 经过一天的纠缠,我终于弄对了。

public function getUserByEmailAndPassword($email, $password) {

    $stmt = $this->conn->prepare("SELECT * FROM seemidavajaon WHERE email = ?");

    $stmt->bind_param('s', $email);

    if ($stmt->execute()) {
        $user = $this->funktsioon( $stmt );
        $stmt = NULL;


        return $user;
    } else {
        return NULL;
    }
}

With a function called "funktsioon" 具有称为“ funktsioon”的功能

public function funktsioon( $stmt ) {
    $RESULT = array();
    $stmt->store_result();
    for ( $i = 0; $i < $stmt->num_rows; $i++ ) {
        $Metadata = $stmt->result_metadata();
        $PARAMS = array();
        while ( $Field = $Metadata->fetch_field() ) {
            $PARAMS[] = &$RESULT[ $i ][ $Field->name ];
        }
        call_user_func_array( array( $stmt, 'bind_result' ), $PARAMS );
        $stmt->fetch();
    }
    return $RESULT;
}

It doesn't check for the password to be right though, so that's a new problem. 它不会检查密码是否正确,所以这是一个新问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM