dstt1818 2014-05-26 13:10
浏览 57
已采纳

MAMP:未定义的方法mysqli_stmt :: get_result()

I am relatively new to using PHP and MySQL and have run into trouble with the following code.

$stmt = $this->conn->prepare("SELECT * FROM users WHERE user_name = ?");
            $stmt->bind_param("s", $username);
            if ($stmt->execute()) {
                $user = $stmt->get_result()->fetch_assoc();
                $stmt->close();
                return $user;
            }

The error: Call to undefined method mysqli_stmt::get_result() is produced on the running of this script presumably due to MAMP not supporting mysqlnd. I have tried to work out how to install the native driver to MAMP but it does not look possible - (I have submitted a bug report and would suggest other MAMP users do so as well).

The line below seems to be the issue:

 $user = $stmt->get_result()->fetch_assoc();

Can anyone suggest an alternative method of producing the same outcome but without mysqlnd?

Many thanks.

  • 写回答

1条回答 默认 最新

  • dongyu3967 2014-07-09 22:57
    关注

    Check your phpinfo(). I have mysqlnd, but only the PDO exension. You can tell by looking a the API Extensions under the mysqlnd section (if mysqlnd is installed).

    Instead of re-writing everything in PDO, this worked for me:

    $stmt = $this->conn->prepare("SELECT name, email, api_key, status, created_at FROM users WHERE email = ?");
        $stmt->bind_param("s", $email);
        if ($stmt->execute()) {
            $stmt->bind_result($name, $email, $api_key, $status, $created_at);
    
            /* fetch values */
            mysqli_stmt_fetch($stmt);
    
            /* set values */
            $user['name'] = $name;
            $user['email'] = $email;
            $user['api_key'] = $api_key;
            $user['created_at'] = $created_at;
    
            $stmt->close();
            return $user;
        } else {
            return NULL;
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python语言实验
  • ¥15 SAP HANA SQL 增加合计行
  • ¥20 用C#语言解决一个英文打字练习器,有偿
  • ¥15 srs-sip外部服务 webrtc支持H265格式
  • ¥15 在使用abaqus软件中,继承到assembly里的surfaces怎么使用python批量调动
  • ¥15 大一C语言期末考试,求帮助🙏🙏
  • ¥15 ch340驱动未分配COM
  • ¥15 Converting circular structure to JSON
  • ¥30 Hyper-v虚拟机相关问题,求解答。
  • ¥15 TSM320F2808PZA芯片 Bootloader