• <legend id='z7Ypi'><style id='z7Ypi'><dir id='z7Ypi'><q id='z7Ypi'></q></dir></style></legend>

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

        mysqli_multi_query 是异步的吗?

        时间:2023-07-31
      3. <small id='yo9pT'></small><noframes id='yo9pT'>

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

                  本文介绍了mysqli_multi_query 是异步的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  $databases = array();
                  $path = '/Path/To/Directory';
                  $main_link = mysqli_connect('localhost', 'USERNAME', 'PASSWORD');
                  $files = scandir($path);
                  $ignore_files = array();
                  
                  foreach($files as $file)
                  {
                      if (!in_array($file, $ignore_files))
                      {
                          $database = substr($file, 0, strpos($file,'.'));
                          $databases[] = $database;
                          mysqli_query($main_link, "DROP DATABASE IF EXISTS $database") or die ("$database 1" . mysqli_error($main_link));
                          mysqli_query($main_link, "CREATE DATABASE $database") or die ("$database 2" .mysqli_error($main_link));
                          $db_link = mysqli_connect('localhost', 'USERNAME', 'PASSWORD', $database);
                          //In here a whole database dump with scheam + data is executed. 
                          mysqli_multi_query($db_link, file_get_contents($path.'/'.$file)) or die ("$database 4" .mysqli_error($db_link));        
                      }   
                  }
                  

                  当运行这个脚本时,它完成得非常快(返回浏览器),但在浏览器说它完成后它仍在运行查询.这是为什么?

                  When running this script it was done very quickly (returned to browser), but it was still running queries after the browser said it was done. Why is this?

                  推荐答案

                  mysqli_query 支持异步查询.请参阅 mysqli_query 上的变更日志.mysqli_multi_query 在手册页上没有特别提到异步.mysqli_multi_query 唯一要做的就是告诉 MySQL 执行一组查询.等待结果由 PHP 决定.

                  mysqli_query supports async queries. See changelog on mysqli_query. mysqli_multi_query does not mention async on the manual page specifically. Only thing mysqli_multi_query does is tell MySQL to execute a bulk set of queries. It's up to PHP to wait for the results.

                  就您的代码而言,您向 MySQL 发送大量 SQL 语句而不等待任何结果.只有当第一条语句失败时,您的 mysqli_multi_query 才会消亡.因此,该函数在第一条语句之后立即返回 true 并移动到下一行.这就是在 PHP 完成后执行查询的原因.MySQL 仍在工作.PHP 已经向前发展.

                  As your code stands, your sending a bulk set of SQL statements to MySQL and not waiting for any results. Only time your mysqli_multi_query will ever die is when the first statement fails. So, that function returns true immediately after the first statement and moves on to the next line. That's why the queries are executing after the PHP is finished. MySQL is still working. PHP has moved on.

                  在继续执行代码之前,最好循环查看每个语句的结果.如果查询在批处理中的任何地方失败,以下内容将死亡.

                  It's best that you loop through the results of each statement before moving on with your code. The following will die if a query fails anywhere in your batch.

                  mysqli_multi_query($db_link, file_get_contents($path.'/'.$file)) or die ("$database 4" .mysqli_error($db_link)); 
                  
                  do {
                      if($result = mysqli_store_result($db_link)){
                          mysqli_free_result($result);
                      }
                  } while(mysqli_next_result($db_link));
                  
                  if(mysqli_error($db_link)) {
                      die(mysqli_error($db_link));
                  }
                  

                  这篇关于mysqli_multi_query 是异步的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在 PHP 中运行 bind_param() 语句? 下一篇:mysqli - fetch_Array 错误调用非对象 mysqli 上的成员函

                  相关文章

                  最新文章

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

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