如何在PHP中使用bind_result()代替get_result()

如何在PHP中使用bind_result()代替get_result(),第1张

如何在PHP中使用bind_result()代替get_result()

假设您无法使用

get_result()
并且想要一系列设备,则可以执行以下 *** 作:

public function getAllDevices($user_id) {    $stmt = $this->conn->prepare("SELECt device_id, device_name, device_info FROM devices WHERe  primary_owner_id = ?");    $stmt->bind_param("i", $user_id);    $stmt->execute();    $stmt->bind_result($id, $name, $info);    $devices = array();    while($stmt->fetch()) {        $tmp = array();        $tmp["id"] = $id;        $tmp["name"] = $name;        $tmp["info"] = $info;        array_push($devices, $tmp);    }    $stmt->close();    return $devices;}

这将创建一个临时数组并将其每一行中的数据存储在其中,然后将其推入主数组。据我所知,您不能

SELECT*
在中使用
bind_result()
。取而代之的是,您将不得不烦恼地键入所有想要的字段。
SELECT



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4990535.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-14
下一篇 2022-11-14

发表评论

登录后才能评论

评论列表(0条)

保存