duancuisan2503 2019-03-27 03:17
浏览 302
已采纳

未捕获的错误:调用未定义的方法mysqli_stmt :: get_result()in

I am new in PHP. I have got one API which have most of functions like below

function getUserByEmail($conn,$email)
    {
        $user = $conn->prepare("SELECT * FROM table_users WHERE email = ?");
        $user->bind_param("s", $email);
        $user->execute();
        $result = $user->get_result();
        $data = $result->fetch_assoc();
        $user->close();
        return $data;
    }

Its working fine in one of my hosting with namecheap which have nd_mysqli enabled. But in my hostgator hosting, its giving error.

Uncaught Error: Call to undefined method mysqli_stmt::get_result() in

I am unable to enable that extension in Hostgator so I want replace it with answers written here or other way.

But I am not getting idea how I can do it.

  • 写回答

1条回答 默认 最新

  • dongyimeng3764 2019-03-27 03:55
    关注

    bind result

    So if the MySQL Native Driver (mysqlnd) driver is not available, and therefore using bind_result and fetch instead of get_result, the code becomes:

    if ($stmt = $mysqli->prepare("SELECT col1,col2 FROM table_users WHERE email = ?")) {
        $stmt->bind_param("s", $email);
        $stmt->execute();
    
        /* bind variables to prepared statement */
        $stmt->bind_result($col1, $col2);
    
        /* fetch values */
        while ($stmt->fetch()) {
            printf("%s %s
    ", $col1, $col2);
        }
    
        /* close statement */
        $stmt->close();
     }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程