gpt4 book ai didi

php - mysqli_stmt_bind_result 有什么优点?

转载 作者:行者123 更新时间:2023-11-29 07:22:04 25 4
gpt4 key购买 nike

我正在将我的 php/mySQL 代码转换为使用准备好的语句。我可以看到准备 SQL 或 DML 以及绑定(bind)参数的值(value)(安全性等)。但我的查询按名称指定选择列表中的字段,并且我使用关联数组来访问它们。

或者,是在像这样的情况下提供帮助,我必须对结果数组中的索引做出假设吗?

$listquery = "SELECT {$tables["result"]}.time, " .
" HOUR({$tables["result"]}.time), " . // [1]
" MINUTE({$tables["result"]}.time), " . // [2]
" SECOND({$tables["result"]}.time), " . // [3]
" {$tables["rider"]}.id, {$tables["rider"]}.gender, " .
" {$tables["rider"]}.first, {$tables["rider"]}.last, " .
" {$tables["result"]}.dnf, " .
" {$tables["race"]}.courseid " .
" FROM {$tables["race"]}, {$tables["result"]}, {$tables["rider"]} " .
" WHERE {$tables["race"]}.raceid = {$tables["result"]}.raceid " .
" AND {$tables["result"]}.riderid = {$tables["rider"]}.id" .
" AND {$tables["race"]}.raceid = ? " .
" ORDER BY {$tables["result"]}.dnf, {$tables["result"]}.time ASC ";

最佳答案

如果您使用MYSQLND驱动程序,则可以使用mysqli_fetch_assocmysqli_stmt_bind_param来获取准备好的查询的结果。这两种方法都没有特别的好处。

如果您没有 MYSQLND 驱动程序,获取 SELECT 查询结果的唯一方法是使用 mysqli_stmt_bind_param

您使用关联数组来指定表名称并不真正相关。您仍在 AND {$tables["race"]}.raceid = ? 中使用占位符,因此您需要准备查询。

关于php - mysqli_stmt_bind_result 有什么优点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35780471/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com