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

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

      <tfoot id='BsL2N'></tfoot>

    2. <legend id='BsL2N'><style id='BsL2N'><dir id='BsL2N'><q id='BsL2N'></q></dir></style></legend>
        <bdo id='BsL2N'></bdo><ul id='BsL2N'></ul>

      Mysqli 不允许多个查询?

      时间:2023-09-24
      <legend id='YwY75'><style id='YwY75'><dir id='YwY75'><q id='YwY75'></q></dir></style></legend>
        <tbody id='YwY75'></tbody>

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

              <bdo id='YwY75'></bdo><ul id='YwY75'></ul>
              <tfoot id='YwY75'></tfoot>
              • <i id='YwY75'><tr id='YwY75'><dt id='YwY75'><q id='YwY75'><span id='YwY75'><b id='YwY75'><form id='YwY75'><ins id='YwY75'></ins><ul id='YwY75'></ul><sub id='YwY75'></sub></form><legend id='YwY75'></legend><bdo id='YwY75'><pre id='YwY75'><center id='YwY75'></center></pre></bdo></b><th id='YwY75'></th></span></q></dt></tr></i><div id='YwY75'><tfoot id='YwY75'></tfoot><dl id='YwY75'><fieldset id='YwY75'></fieldset></dl></div>
                本文介绍了Mysqli 不允许多个查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我正在 PHP 中运行一个脚本,该脚本使用循环为 MySQL 创建一个字符串查询.

                I am running a script in PHP that uisng a loop creates a string query for MySQL.

                执行脚本后出现以下错误:

                After executing the script I get the following error:

                您的 SQL 语法有错误;请查看手册对应于您的 MySQL 服务器版本以使用正确的语法'UPDATE BANNERS SET pos=1 WHERE BID=5; 附近更新横幅集pos=2 WHERE BID=1' 在第 2 行"

                "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UPDATE BANNERS SET pos=1 WHERE BID=5; UPDATE BANNERS SET pos=2 WHERE BID=1' at line 2"

                在错误之后我回显查询,它看起来像这样:

                right after the error I echo the query and it looks like this:

                UPDATE BANNERS SET pos=0 WHERE BID=6;
                UPDATE BANNERS SET pos=1 WHERE BID=5;
                UPDATE BANNERS SET pos=2 WHERE BID=1;
                

                当我将其复制并粘贴到 phpmyadmin 中时,它显然可以毫无问题地执行.

                When I copy and paste it into phpmyadmin, it obviously gets executed without any problem.

                有什么想法吗?

                这是PHP代码:

                有一个看起来像这样的数组:

                There is an array that looks like this:

                $order[0] = 'tr_6';
                $order[1] = 'tr_5';
                $order[2] = 'tr_1';
                
                $query = "";
                
                foreach($order as $pos => $value){
                   $idvalue = str_replace('tr_','',$value);
                   $query .= "UPDATE BANNERS  SET pos=$pos WHERE BID=$idvalue;
                ";
                }
                
                mysqli_query($connection,$query) or die(mysqli_error($connection)."<br/>$query");
                

                谢谢!

                推荐答案

                mysqli 允许使用 mysqli_multiple_query 函数进行多次查询,如下所示:

                mysqli allow multiple queries with mysqli_multiple_query function like this:

                $query  = "SELECT CURRENT_USER();";
                $query .= "SELECT Name FROM City ORDER BY ID LIMIT 20, 5";
                
                /* execute multi query */
                if (mysqli_multi_query($link, $query)) {
                    do {
                        /* store first result set */
                        if ($result = mysqli_store_result($link)) {
                            while ($row = mysqli_fetch_row($result)) {
                                printf("%s
                ", $row[0]);
                            }
                            mysqli_free_result($result);
                        }
                        /* print divider */
                        if (mysqli_more_results($link)) {
                            printf("-----------------
                ");
                        }
                    } while (mysqli_next_result($link));
                }
                

                请注意,每次查询后都需要使用分号.

                note that you need to use semicolon after each query.

                这篇关于Mysqli 不允许多个查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:将数组转换为单独的字符串 下一篇:mysqli_real_escape_string() 期望参数 1 是 mysqli,布尔值

                相关文章

                最新文章

              • <tfoot id='7JNIZ'></tfoot>
                <legend id='7JNIZ'><style id='7JNIZ'><dir id='7JNIZ'><q id='7JNIZ'></q></dir></style></legend>

                  <small id='7JNIZ'></small><noframes id='7JNIZ'>

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