- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我试图绑定(bind)参数(为了安全),然后将结果放入一个数组中,所以我创建了如下代码。问题是它不起作用:$arr
为空。 (顺便说一句,我知道 getList
中的查询有效。)
if ($stmt = mysqli_prepare($con, "call getList(?)")) {
mysqli_stmt_bind_param($stmt, 's', $userInputSearch);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$arr = mysqli_fetch_all($result, MYSQLI_ASSOC);
$jsonArr = json_encode($arr);
echo $jsonArr;
请注意,在使用 mysqli_query()
时,我已经让 mysqli_fetch_all
工作。
关于 mysqli_fetch_all引用,我发现了这条评论:
Also, mysqli_fetch_all works only for buffered result sets, which are the default for mysqli_query. MYSQLI_USE_RESULT will be supported in 5.3.4+ However, it makes little sense to use it this way, materialising unbuffered sets. In this case choose STORE_RESULT, and fetch_all won't copy the data, but reference it, as it is stored already in mysqlnd.
我发现准备好的语句返回未缓冲的结果,所以我尝试使用 $result = mysqli_stmt_store_result($stmt)
而不是 $result = mysqli_stmt_get_result($stmt);
但是那没有帮助。
这让我并没有完全不知所措——我知道我可以循环一次加载一行数据,但我真的不想在 PHP 中循环只是为了做一些简单的事情来自准备好的语句的数组。有没有办法将结果集作为一个对象来获取和处理?
最佳答案
我刚刚重读了文档...
我现在不可能测试 mysql。
但只是猜测:
mysqli_fetch_all ( mysqli_result $result ...
Parameters result Procedural style only: A result set identifierreturned by mysqli_query(), mysqli_store_result() ormysqli_use_result().
我想强调所有函数 mysqli_query(), mysqli_store_result() mysqli_use_result()
属于 mysqli 类,而不属于 stmt
并且它们返回类型 mysqli_result
但您正在尝试使用 mysqli_stmt_get_result($stmt);
mysqli_result mysqli_stmt_get_result ( mysqli_stmt $stmt )
...Return Values
Returns a resultset or FALSE on failure.
所以这个函数返回类型resultset
而不是mysqli_result
。
因此您必须更改代码以不使用 mysqli_stmt
所以改变:
if ($stmt = mysqli_prepare($con, "call getList(?)")) {
mysqli_stmt_bind_param($stmt, 's', $userInputSearch);
mysqli_stmt_execute($stmt);
到
$result = mysqli_query ( $con , "call getList(".mysqli_real_escape_string($userInputSearch).")" );
,或只需更改您的线路:
$arr = mysqli_fetch_all($result, MYSQLI_ASSOC);
到
$arr = array()
while ($row = $result->fetch_array())
{
arr[] = $row ;
}
如有错误请见谅,目前无法跟踪调试,希望对您有所帮助。
关于php - mysqli_stmt_get_result 和 mysqli_fetch_all 不兼容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28630617/
我刚刚将某些内容从本地计算机推送到实时站点,但到处都是空白页面。当我使用所有东西时,我将问题追踪到 mysqli_fetch_all 。它为什么要这样做?我该如何解决它?如果我使用 mysqli_fe
我有一个通过 mysqli 实例访问的 MySQL 数据库。在我导出数据库并将其导入新服务器(现在使用新服务器)之前,所有 CRUD 操作都运行良好。现在,每个表都运行良好,并通过简单的 SELECT
我曾经使用 PHP 处理 Oracle DB。 $strSQL = oci_parse($c1, "SELECT * FROM tb_users"); oci_execute($strSQL); $N
我有一个 php-mysqli 代码可以找到我的本地服务器但是在我的服务器上使用它我得到一个 Fatal error: Call to undefined function mysqli_fetch_
我看到 mysqli_fetch_array() 之间的比较和 mysqli_fetch_all()这就是说 mysqli_fetch_all()这将需要更多的内存,我将不得不遍历数组。 mysqli
我有一个查询,该查询从数据库获取有关画廊类别的信息并将其加载到数组中,以便在整个脚本的多个位置使用。 $q_gals = "SELECT `gal_id`, `gal_name` FROM `cms_
此代码片段仅在我与 PDO 建立连接但我希望与 mysqli 建立连接时才有效。--> link prepare($query); $statement->execute();
据我了解 $data = mysqli_fetch_all($result, MYSQLI_ASSOC) 将使 $data 关联数组包含关联数组? 假设我有一个名为 users 的表,包含 3 列:“
这个问题在这里已经有了答案: Fatal error: Call to undefined method mysqli_result::fetch_all() (3 个答案) 关闭 3 年前。 我的
这个问题在这里已经有了答案: Alternative to mysqli_fetch_all needed (2 个答案) 关闭 4 年前。 在通过 XAMPP 在本地主机上进行开发时,我在代码中使
我对 ORACLE 数据库上的表使用 PHP 分页 $strSQL = oci_parse($c1, " SELECT L.LINEID, L.LINENAME, L.
目前我有一些效果: 会输出一些效果: Array ( [0] => Array ( [type_id] => 1 [type_name] => In Stock [typ
我试图绑定(bind)参数(为了安全),然后将结果放入一个数组中,所以我创建了如下代码。问题是它不起作用:$arr 为空。 (顺便说一句,我知道 getList 中的查询有效。) if ($stmt
我遇到了一个有趣的问题,但我不知道如何解决。我在 XAMPP 上创建我的网站,它工作正常。但是一旦它被上传到服务器,我的一部分 php 代码就没有被执行。我在整个代码中放置了 echo 语句以确定我的
几天前,我从 Windows 迁移到 Ubuntu 作为我的服务器。我一直做得很好,但从第一天起我就遇到了 Apache 的问题。 我终于到了某个地方,但现在我在我的 PHP 日志中使用 MySQLi
This question already has answers here: mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/my
我有一个带主机的基本站点,最近 mysqli_fetch_all 命令似乎已停止工作,因为我收到消息: Fatal error: Call to undefined function mysqli_f
我是一名优秀的程序员,十分优秀!