如何使用store_result()获取数据?
我在执行准备好的语句后尝试使用 $stmt->store_result()
时遇到问题。手册上说“从准备好的语句中传输结果集”,但是传输到哪里呢?
理想情况下,我想使用它,一切都很好并且缓冲在内存中,就像 $mysqli->query()
返回一样。
PHP 文档示例使得使用 store_result()
的唯一充分理由似乎是获取行数。
理想情况下,我需要一些可以从准备好的语句中获取整个结果集并对其执行诸如 fetch_rows 之类的操作的东西。我确实通过扩展 mysqli_stmt 类并使用一些向后方法添加 fetch_assoc 函数来破解它,但如果我可以缓冲所有数据,我真的很想删除该黑客进入记忆。
所以我想我的简短问题是,我知道 store_result()
的作用,但你如何使用它?
(老实说,如果它在防止 SQL 注入攻击、消除变量和使我的 SQL 看起来非常漂亮,带有所有这些问号。)
I'm having trouble trying to use $stmt->store_result()
after executing a prepared statement. The manual says "Transfers a result set from a prepared statement", but to where?
I would ideally like to use it, all nice and buffered in memory, like $mysqli->query()
returns.
The PHP documentation examples make it seem like the only good reason to use store_result()
is to get the number of rows.
Ideally, I need something that can get the entire result set from a prepared statement and do something like fetch_rows on it. I DID hack the mysqli_stmt
class by extending it and adding a fetch_assoc
function using some backwards methods, but I would really like to remove that hack if I can get all my data buffered into memory.
So I guess my short question is, I know what store_result()
does, but how do you USE it?
(And honestly, I wouldn't even be using $mysqli->prepare()
to get a stmt, if it wasn't so damn useful in preventing SQL injection attacks, sterilizing variables, and making my SQL look so nice and pretty with all those question marks.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
store_result()
唯一做的事情就是将结果从 MySQL 移动到 PHP 内存中。它不是很有用,因为您仍然需要将结果获取到 PHP 变量中。您正在寻找的是
get_result()
。该函数将从 MySQL 获取结果并将其存储在 PHP 内存中,另外返回一个熟悉的 mysqli_result 对象。The only thing that
store_result()
does is it moves the result from MySQL into PHP memory. It's not very useful since you still need to fetch the results into PHP variables.What you are looking for is
get_result()
. This function will fetch results from MySQL and store them in PHP memory, additionally returning a familiarmysqli_result
object.