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 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)