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

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

      <legend id='Ej4kd'><style id='Ej4kd'><dir id='Ej4kd'><q id='Ej4kd'></q></dir></style></legend>
      <tfoot id='Ej4kd'></tfoot>

      如何确保我从 MySQLi::multi_query 中捕获到所有错误

      时间:2023-07-30
          <i id='ecMnG'><tr id='ecMnG'><dt id='ecMnG'><q id='ecMnG'><span id='ecMnG'><b id='ecMnG'><form id='ecMnG'><ins id='ecMnG'></ins><ul id='ecMnG'></ul><sub id='ecMnG'></sub></form><legend id='ecMnG'></legend><bdo id='ecMnG'><pre id='ecMnG'><center id='ecMnG'></center></pre></bdo></b><th id='ecMnG'></th></span></q></dt></tr></i><div id='ecMnG'><tfoot id='ecMnG'></tfoot><dl id='ecMnG'><fieldset id='ecMnG'></fieldset></dl></div>

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

            <bdo id='ecMnG'></bdo><ul id='ecMnG'></ul>
              <tbody id='ecMnG'></tbody>
            <legend id='ecMnG'><style id='ecMnG'><dir id='ecMnG'><q id='ecMnG'></q></dir></style></legend>
            • <small id='ecMnG'></small><noframes id='ecMnG'>

                本文介绍了如何确保我从 MySQLi::multi_query 中捕获到所有错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                multi_query 文档 说:

                如果第一条语句失败,则返回 FALSE.要从其他语句中检索后续错误,您必须先调用 mysqli_next_result().

                Returns FALSE if the first statement failed. To retrieve subsequent errors from other statements you have to call mysqli_next_result() first.

                next_result 的 文档 说:

                成功时返回 TRUE,失败时返回 FALSE.

                Returns TRUE on success or FALSE on failure.

                最后,multi_query 文档中发布的示例使用 next_result 的返回值来确定何时不再有查询;例如停止循环:

                Finally, the example posted in the docs for multi_query use the return value from next_result to determine when there are no more queries; e.g. to stop looping:

                <?php
                $mysqli = new mysqli("localhost", "my_user", "my_password", "world");
                
                /* check connection */
                if (mysqli_connect_errno()) {
                    printf("Connect failed: %s
                ", mysqli_connect_error());
                    exit();
                }
                
                $query  = "SELECT CURRENT_USER();";
                $query .= "SELECT Name FROM City ORDER BY ID LIMIT 20, 5";
                
                    /* execute multi query */
                    if ($mysqli->multi_query($query)) {
                        do {
                            /* store first result set */
                            if ($result = $mysqli->store_result()) {
                                while ($row = $result->fetch_row()) {
                                    printf("%s
                ", $row[0]);
                                }
                                $result->free();
                            }
                            /* print divider */
                            if ($mysqli->more_results()) {
                                printf("-----------------
                ");
                            }
                        } while ($mysqli->next_result()); // <-- HERE!
                    }
                
                    /* close connection */
                    $mysqli->close();
                    ?>
                

                我不知道提供的查询数量,也不知道我将要执行的 SQL.因此,我不能仅将查询数量与返回结果的数量进行比较.然而,如果第三个查询是损坏的查询,我想向用户显示一条错误消息.但我似乎没有办法判断 next_result 失败是因为没有更多的查询要执行,还是因为 SQL 语法有错误.

                I don't know the number of queries provided, nor do I know anything about the SQL that I'm going to execute. I therefore can't just compare the number of queries against the number of returned results. Yet I want to display an error message to the user if, say, the third query was the broken query. But I don't seem to have a way to tell if next_result failed because there were no more queries to execute, or if it's because there was an error in the SQL syntax.

                如何检查所有查询是否有错误?

                How can I check all the queries for errors?

                推荐答案

                尽管文档中有代码示例,但也许更好的方法是这样的:

                Despite the code example in the docs, perhaps the better method would be something like this:

                if ($mysqli->multi_query(...)) {
                  do {
                    // fetch results
                
                    if (!$mysqli->more_results()) {
                      break;
                    }
                    if (!$mysqli->next_result()) {
                      // report error
                      break;
                    }
                  } while (true);
                }
                

                这篇关于如何确保我从 MySQLi::multi_query 中捕获到所有错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:使用 PHP 在 HTML 表格中显示 MySQL 结果 下一篇:是否可以将 mysqli_fetch_object 与准备好的语句一起

                相关文章

                最新文章

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

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

                    <legend id='f0Ewl'><style id='f0Ewl'><dir id='f0Ewl'><q id='f0Ewl'></q></dir></style></legend>