<tfoot id='U56gT'></tfoot>
    1. <i id='U56gT'><tr id='U56gT'><dt id='U56gT'><q id='U56gT'><span id='U56gT'><b id='U56gT'><form id='U56gT'><ins id='U56gT'></ins><ul id='U56gT'></ul><sub id='U56gT'></sub></form><legend id='U56gT'></legend><bdo id='U56gT'><pre id='U56gT'><center id='U56gT'></center></pre></bdo></b><th id='U56gT'></th></span></q></dt></tr></i><div id='U56gT'><tfoot id='U56gT'></tfoot><dl id='U56gT'><fieldset id='U56gT'></fieldset></dl></div>
      • <bdo id='U56gT'></bdo><ul id='U56gT'></ul>

    2. <legend id='U56gT'><style id='U56gT'><dir id='U56gT'><q id='U56gT'></q></dir></style></legend>
    3. <small id='U56gT'></small><noframes id='U56gT'>

        是否可以将 mysqli_fetch_object 与准备好的语句一起

        时间:2023-07-30

      1. <tfoot id='jZ9gL'></tfoot>
        <legend id='jZ9gL'><style id='jZ9gL'><dir id='jZ9gL'><q id='jZ9gL'></q></dir></style></legend>
            <tbody id='jZ9gL'></tbody>

        • <i id='jZ9gL'><tr id='jZ9gL'><dt id='jZ9gL'><q id='jZ9gL'><span id='jZ9gL'><b id='jZ9gL'><form id='jZ9gL'><ins id='jZ9gL'></ins><ul id='jZ9gL'></ul><sub id='jZ9gL'></sub></form><legend id='jZ9gL'></legend><bdo id='jZ9gL'><pre id='jZ9gL'><center id='jZ9gL'></center></pre></bdo></b><th id='jZ9gL'></th></span></q></dt></tr></i><div id='jZ9gL'><tfoot id='jZ9gL'></tfoot><dl id='jZ9gL'><fieldset id='jZ9gL'></fieldset></dl></div>

                • <bdo id='jZ9gL'></bdo><ul id='jZ9gL'></ul>

                  <small id='jZ9gL'></small><noframes id='jZ9gL'>

                  本文介绍了是否可以将 mysqli_fetch_object 与准备好的语句一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我看到的所有使用 mysqli_fetch_object 的示例都使用 mysql_query(),我无法让它与准备好的语句一起工作.有谁知道这段代码有什么问题,因为 fetch_object 返回 null.

                  All the examples I see using mysqli_fetch_object use mysql_query(), I cannot get it to work with prepared statements. Does anyone know what is wrong with this code snippet, as fetch_object returns null.

                  $sql = "select 1 from dual";
                  printf("preparing %s
                  ", $sql);
                  $stmt = $link->prepare($sql);
                  printf("prepare statement %s
                  ", is_null($stmt) ? "is null" : "created");
                  $rc = $stmt->execute();
                  printf("num rows is %d
                  ", $stmt->num_rows);
                  $result = $stmt->result_metadata();
                  printf("result_metadata %s
                  ", is_null($result) ? "is null" : "exists");
                  $rc = $result->fetch_object();
                  printf("fetch object returns %s
                  ", is_null($rc) ? "NULL" : $rc);
                  $stmt->close();
                  

                  输出为:

                  preparing select 1 from dual
                  prepare statement created
                  num rows is 0
                  result_metadata exists
                  fetch object returns NULL
                  

                  推荐答案

                  我不相信界面是这样工作的.

                  I don't believe the interface works like that.

                  通过文档和示例(http://www.php.net/manual/en/mysqli.prepare.php) 似乎 $stmt->execute() 不返回结果集,而是一个指示成功/失败的布尔值(http://www.php.net/manual/en/mysqli-stmt.execute.php).要实际获得结果,您需要使用 $stmt->bind_result (http://www.php.net/manual/en/mysqli-stmt.bind-result.php).

                  Going by the documentation and examples (http://www.php.net/manual/en/mysqli.prepare.php) it seems that $stmt->execute() does not return a resultset, but a boolean indicating success / failure (http://www.php.net/manual/en/mysqli-stmt.execute.php). To actually get the result, you need to bind variables to the resultset (aftere the execute call) using $stmt->bind_result (http://www.php.net/manual/en/mysqli-stmt.bind-result.php).

                  完成所有这些之后,您可以重复调用 $stmt->fetch() () 以使用当前行中的列值填充绑定变量.我没有看到任何提及 $stmt->fetch_object() 的内容,也没有看到该接口如何与描述的变量绑定方案一起工作.

                  After you did all that, you can do repeated calls to $stmt->fetch() () to fill the bound variables with the column values from the current row. I don't see any mention of $stmt->fetch_object() nor do I see how that interface could work with a variable binding scheme like described.

                  这就是从 mysqli 准备好的语句中获取正常"结果的故事.

                  So this is the story for "normal" result fetching from mysqli prepared statments.

                  在您的代码中,我怀疑存在错误,或者至少我不确定您是否打算这样做.你行:

                  In your code, there is something that I suspect is an error, or at least I am not sure you intended to do this. You line:

                  $result = $stmt->result_metadata();
                  

                  将结果集元数据(本身表示为结果集)分配给 $result 变量.根据文档 (http://www.php.net/manual/en/mysqli-stmt.result-metadata.php) 您只能在这些特殊"类型的结果集上使用方法的一个子集,而 fetch_object() 不是其中之一(至少它是未明确列出).

                  assignes the resultset metadata, which is itself represented as a resultset, to the $result variable. According to the doc (http://www.php.net/manual/en/mysqli-stmt.result-metadata.php) you can only use a subset of the methods on these 'special' kinds of resultsets, and fetch_object() is not one of them (at least it is not explicitly listed).

                  也许是这些元数据结果集没有实现 fetch_object() 的错误,也许你应该在 bugs 提交错误.mysql.com 关于那个.

                  Perhaps it is a bug that fetch_object() is not implemented for these metadata resultsets, perhaps you should file a bug at bugs.mysql.com about that.

                  这篇关于是否可以将 mysqli_fetch_object 与准备好的语句一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何确保我从 MySQLi::multi_query 中捕获到所有错误 下一篇:使用 MySQLI 正确转义 |查询准备好的语句

                  相关文章

                  最新文章

                    <bdo id='pU8jc'></bdo><ul id='pU8jc'></ul>

                  1. <tfoot id='pU8jc'></tfoot>

                    <small id='pU8jc'></small><noframes id='pU8jc'>

                  2. <legend id='pU8jc'><style id='pU8jc'><dir id='pU8jc'><q id='pU8jc'></q></dir></style></legend>

                    <i id='pU8jc'><tr id='pU8jc'><dt id='pU8jc'><q id='pU8jc'><span id='pU8jc'><b id='pU8jc'><form id='pU8jc'><ins id='pU8jc'></ins><ul id='pU8jc'></ul><sub id='pU8jc'></sub></form><legend id='pU8jc'></legend><bdo id='pU8jc'><pre id='pU8jc'><center id='pU8jc'></center></pre></bdo></b><th id='pU8jc'></th></span></q></dt></tr></i><div id='pU8jc'><tfoot id='pU8jc'></tfoot><dl id='pU8jc'><fieldset id='pU8jc'></fieldset></dl></div>