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

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

  • <tfoot id='z6dD5'></tfoot>

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

      1. <small id='z6dD5'></small><noframes id='z6dD5'>

      2. 严格的标准:mysqli_multi_query 的 mysqli_next_result() 错

        时间:2023-07-31

      3. <legend id='FxqTu'><style id='FxqTu'><dir id='FxqTu'><q id='FxqTu'></q></dir></style></legend>
          <tbody id='FxqTu'></tbody>

      4. <small id='FxqTu'></small><noframes id='FxqTu'>

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

                  本文介绍了严格的标准:mysqli_multi_query 的 mysqli_next_result() 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我曾尝试使用 multi_query,但我不断收到严格的标准消息.

                  I have tried using multi_query but I keep getting a strict Standards message popping up.

                  $querystring = "INSERT INTO responses VALUES('1', '2', '3', '4'); INSERT INTO responses VALUES('1', '2', '3', '4')";
                  
                  if (mysqli_multi_query($db, $querystring)) {
                     do {
                         if ($result = mysqli_store_result($db)) {
                             //
                         }
                     } while (mysqli_next_result($db));
                  }
                  echo "end";
                  

                  我得到的错误信息是:

                  严格标准:mysqli_next_result():没有下一个结果集.请调用mysqli_more_results()/mysqli::more_results()检查是否调用这个函数/方法

                  Strict Standards: mysqli_next_result(): There is no next result set. Please, call mysqli_more_results()/mysqli::more_results() to check whether to call this function/method

                  我尝试添加和删除 -; 但没有成功.

                  I've tried adding and removing -; but had no luck.

                  推荐答案

                  虽然 pipodesign 更正了 $querystring 中的错误并缓解了问题,但并未提供有关 Strict Standards 错误的实际解决方案.

                  While pipodesign corrected the error within the $querystring and alleviated the problem, the actual solution was not provided regarding the Strict Standards error.

                  我不同意 SirBT 的建议,没有必要从 DO WHILE 更改为 WHILE.

                  I disagree with SirBT's advice, changing from DO WHILE to WHILE is not necessary.

                  您收到的严格标准消息非常有用.要服从,请使用:

                  The Strict Standards message that you receive is quite informative. To obey, use this:

                  do{} while(mysqli_more_results($db) && mysqli_next_result($db));
                  

                  然后,您无需在循环内部编写条件退出或中断,因为 while 条件将在第一次出现错误时中断循环.*注意,如果第一个查询有错误,则 do-while 之前的 if 语句将拒绝进入循环.

                  Then, there is no need for you to write a conditional exit or break inside of the loop because the while condition will break the loop on the first occurrence of an error. *note, the if statement before the do-while will deny entry to the loop if the first query has an error.

                  在您的示例中,您只运行 INSERT 查询,因此您不会收到任何要处理的结果集.如果要计算添加了多少行,请使用 mysqli_affected_rows().

                  In your example, you are only running INSERT queries, so you won't receive any result sets to process. If you want to count how many rows you've added, use mysqli_affected_rows().

                  作为您问题的完整解决方案:

                  As a complete solution for your question:

                  if(mysqli_multi_query($db,$querystring)){
                      do{
                          $cumulative_rows+=mysqli_affected_rows($db);
                      } while(mysqli_more_results($db) && mysqli_next_result($db));
                  }
                  if($error_mess=mysqli_error($db)){echo "Error: $error_mess";}
                  echo "Cumulative Affected Rows: $cumulative_rows";
                  

                  输出:

                   // if no errors
                  Cumulative Affected Rows: 2
                  
                  // if error on second query
                  Error: [something]
                  Cumulative Affected Rows: 1
                  
                  // if error on first query
                  Error: [something]
                  Cumulative Affected Rows: 0
                  

                  <小时>

                  后期

                  由于刚接触 mysqli 的人在这篇文章中遇到了困难,我将提供一个通用但强大的代码段来使用 multi_query() 处理有/没有结果集的查询,并添加一个功能来显示正在处理数组中的哪个查询...

                  Since people new to mysqli are stumbling across this post, I'll offer a general yet robust snippet to handle queries with/without result sets using multi_query() and add a feature to display which query in the array is being handled...

                  经典的IF(){DO{} WHILE}"语法:

                  if(mysqli_multi_query($mysqli,implode(';',$queries))){
                      do{
                          echo "<br><br>",key($queries),": ",current($queries);  // display key:value @ pointer
                          if($result=mysqli_store_result($mysqli)){   // if a result set
                              while($rows=mysqli_fetch_assoc($result)){
                                  echo "<br>Col = {$rows["Col"]}";
                              }
                              mysqli_free_result($result);
                          }
                          echo "<br>Rows = ",mysqli_affected_rows($mysqli); // acts like num_rows on SELECTs
                      } while(next($queries) && mysqli_more_results($mysqli) && mysqli_next_result($mysqli));
                  }
                  if($mysqli_error=mysqli_error($mysqli)){
                      echo "<br><br>",key($queries),": ",current($queries),"Syntax Error:<br>$mysqli_error";  // display array pointer key:value
                  }
                  //if you want to use the snippet again...
                  $mysqli_error=null; // clear variables
                  reset($queries); // reset pointer
                  

                  <小时>

                  重新发明的轮子WHILE{}"语法(...对于那些不喜欢测试后循环的人):


                  Reinvented Wheel "WHILE{}" Syntax (...for those who don't like post-test loops):

                  while((isset($multi_query) && (next($queries) && mysqli_more_results($mysqli) && mysqli_next_result($mysqli))) || (!isset($multi_query) && $multi_query=mysqli_multi_query($mysqli,implode(';',$queries)))){
                      echo "<br><br>",key($queries),": ",current($queries);  // display array pointer key:value
                      if($result=mysqli_store_result($mysqli)){
                          while($rows=mysqli_fetch_assoc($result)){
                              echo "<br>Col = {$rows["Col"]}";
                          }
                          mysqli_free_result($result);
                      }
                      echo "<br>Rows = ",mysqli_affected_rows($mysqli); // acts like num_rows on SELECTs
                  }
                  if($mysqli_error=mysqli_error($mysqli)){
                      echo "<br><br>",key($queries),": ",current($queries),"Syntax Error:<br>$mysqli_error";  // display array pointer key:value
                  }
                  //if you want to use the snippet again...
                  $multi_query=$mysqli_error=null; // clear variables
                  reset($queries); // reset pointer
                  

                  因此,给出以下查询的任一片段都将提供相同的输出:

                  So, either snippet given the following queries will offer the same output:

                  查询数组:

                  $queries[]="SELECT * FROM `TEST`";
                  $queries[]="INSERT INTO `TEST` (Col) VALUES ('string1'),('string2')";
                  $queries[]="SELECT * FROM `TEST`";
                  $queries[]="DELETE FROM `TEST` WHERE Col LIKE 'string%'";
                  

                  输出:

                  0: SELECT * FROM `TEST`
                  Rows = 0
                  
                  1: INSERT INTO `TEST` (Col) VALUES ('string1'),('string2')
                  Rows = 2
                  
                  2: SELECT * FROM `TEST`
                  Col = string1
                  Col = string2
                  Rows = 2
                  
                  3: DELETE FROM `TEST` WHERE Col LIKE 'string%'
                  Rows = 2
                  

                  根据您的需要修改我的片段.如果您发现错误,请发表评论.

                  Modify my snippets per your needs. Leave a comment if you discover a bug.

                  这篇关于严格的标准:mysqli_multi_query 的 mysqli_next_result() 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:MySQLi 相当于 mysql_result()? 下一篇:如何解决“致命错误:找不到类‘MySQLi’"?

                  相关文章

                  最新文章

                • <tfoot id='34K6R'></tfoot>

                  • <bdo id='34K6R'></bdo><ul id='34K6R'></ul>

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

                      <small id='34K6R'></small><noframes id='34K6R'>