bind_result 成一个数组 PHP mysqli 准备语句 [英] bind_result into an array PHP mysqli prepared statement
问题描述
想知道如何将 PHP 准备好的语句的结果绑定到数组中,然后如何调用它们.例如这个查询
wondering how i could bind the results of a PHP prepared statement into an array and then how i could go about calling them. for example this query
$q = $DBH->prepare("SELECT * FROM users WHERE username = ?");
$q->bind_param("s", $user);
$q->execute();
这将返回用户名、电子邮件和 ID 的结果.想知道我是否可以将它绑定到一个数组中,然后将它存储在一个变量中,以便我可以在整个页面中调用它?
and this would return the results the username, email, and id. wondering if i could bind it in an array, and then store it in a variable so i could call it throughout the page?
推荐答案
PHP 5.3 引入 mysqli_stmt::get_result,它返回一个结果集对象.然后您可以调用 mysqli_result::fetch_array() 或mysqli_result::fetch_assoc().不过,它仅适用于本机 MySQL 驱动程序.
PHP 5.3 introduced mysqli_stmt::get_result, which returns a resultset object. You can then call mysqli_result::fetch_array() or mysqli_result::fetch_assoc(). It's only available with the native MySQL driver, though.
这篇关于bind_result 成一个数组 PHP mysqli 准备语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!