1

I am working on a login and register android project. I tried different solutions for this PHP error, but none of them helped me.

I'm getting this error:

Call to undefined method mysqli_stmt::get_result() in ... on line 59

And line 59 is: $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.

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;
    }
}

1 Answers1

0

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"

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.