<small id='52u8Q'></small><noframes id='52u8Q'>

    <legend id='52u8Q'><style id='52u8Q'><dir id='52u8Q'><q id='52u8Q'></q></dir></style></legend>
      <bdo id='52u8Q'></bdo><ul id='52u8Q'></ul>
    1. <tfoot id='52u8Q'></tfoot>

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

      1. PHP MySQLi 多次插入

        时间:2023-07-31
        <legend id='h3LnQ'><style id='h3LnQ'><dir id='h3LnQ'><q id='h3LnQ'></q></dir></style></legend>

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

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

          1. <tfoot id='h3LnQ'></tfoot>
                  <bdo id='h3LnQ'></bdo><ul id='h3LnQ'></ul>
                • 本文介绍了PHP MySQLi 多次插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想知道准备好的语句是否与具有多个 VALUES 的普通 mysql_query 工作相同.

                  I'm wondering if prepared statements work the same as a normal mysql_query with multiple VALUES.

                  INSERT INTO table (a,b) VALUES ('a','b'), ('c','d');
                  

                  VS

                  $sql = $db->prepare('INSERT INTO table (a,b) VALUES (?, ?);
                  

                  如果我在循环中使用准备好的语句,MySQL 是在后台优化插入以使其像在那里的第一段代码中一样工作,还是就像在循环中运行第一段代码一样每次值?

                  If I use the prepared statement in a loop, is MySQL optimizing the insert in the background to work like it would in the first piece of code there, or is it just like running the first piece of code inside a loop with one value each time ?

                  推荐答案

                  我继续进行了一个测试,其中一个查询使用准备好的语句,另一个构建整个查询然后执行该查询.我可能没有让我想知道的内容易于理解.

                  I went ahead and ran a test where one query uses a prepared statement, and the other builds the entire query then executes that. I'm probably not making what I'm wanting to know easy to understand.

                  这是我的测试代码.我在想准备好的语句会阻止执行,直到调用 $stmt->close() 来优化它或其他东西.但情况似乎并非如此,因为使用 real_escape_string 构建查询的测试至少要快 10 倍.

                  Here's my test code. I was thinking prepared statements sort of held back execution until a $stmt->close() was called to optimize it or something. That doesn't appear to be the case though as the test that builds the query using real_escape_string is at least 10 times faster.

                  <?php
                  
                  $db = new mysqli('localhost', 'user', 'pass', 'test');
                  
                  $start = microtime(true);
                  $a = 'a';
                  $b = 'b';
                  
                  $sql = $db->prepare('INSERT INTO multi (a,b) VALUES(?, ?)');
                  $sql->bind_param('ss', $a, $b);
                  for($i = 0; $i < 10000; $i++)
                  {
                      $a = chr($i % 1);
                      $b = chr($i % 2);
                      $sql->execute();
                  }
                  $sql->close();
                  
                  echo microtime(true) - $start;
                  
                  $db->close();
                  
                  ?>
                  

                  这篇关于PHP MySQLi 多次插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何确保 MySQL 中的值在 PHP 中保持其类型? 下一篇:mysqli_fetch_array 只返回一个结果

                  相关文章

                  最新文章

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

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

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

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