<tfoot id='O58CQ'></tfoot>
          <bdo id='O58CQ'></bdo><ul id='O58CQ'></ul>
      1. <small id='O58CQ'></small><noframes id='O58CQ'>

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

      3. PHP mysqli 命令不同步;你现在不能运行这个命令

        时间:2023-07-30

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

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

                <bdo id='uulQO'></bdo><ul id='uulQO'></ul>
                  <tbody id='uulQO'></tbody>
              • <legend id='uulQO'><style id='uulQO'><dir id='uulQO'><q id='uulQO'></q></dir></style></legend>
              • <tfoot id='uulQO'></tfoot>

                • 本文介绍了PHP mysqli 命令不同步;你现在不能运行这个命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  在我的数据库中,我有一些存储过程.

                  In my db I have some stored procedures.

                  我想打电话给其中一个,根据我从这个程序得到的结果,我会决定天气是否打电话给第二个.

                  I want to call the one of them, and according to the results I get from this procedure, i will determine weather to call the second one or not.

                  正如您在 isUserValid() 方法中看到的,我使用了 $result->free_results()

                  As you can see in the isUserValid() method I've used $result->free_results()

                  但仍然在调用另一个过程时我得到:命令不同步;你现在不能运行这个命令

                  but still when calling the other procedure I get: Commands out of sync; you can't run this command now

                  这是我对 db 函数的调用:

                  This is my calling to the db functions:

                      /**
                       * Run a new query on the db.
                       * this will open an close the connection to the db
                       * @param $query string the query to run
                       * @param $verifyAccessToken boolean true if user validation is needed before query is executed, false otherwise
                       * @return bool|mysqli_result the result of the query if any or true or false in a non query
                       * @throws Exception on connection and query errors
                       */
                      private function queryDb($query,$verifyAccessToken)
                      {
                         // if ($this->test)
                  //            echo $query . "<br>";
                          //create a new mysqli connection
                          $mysqli = new mysqli($this->DB_HOST, $this->DB_USER, $this->DB_PASS, $this->DB_NAME);
                          //set the charset for the connection
                          if (!$mysqli->set_charset("utf8"))
                          {
                              $mysqli->close();
                              throw new Exception ("Error setting UTF 8 DB connection");
                          }
                          //check if the connection was ok
                          if (mysqli_connect_errno())
                          {
                              $mysqli->close();
                              throw new Exception("Error connecting DB");
                          }
                  
                          //if verification is needed - verify access token
                         if ($verifyAccessToken && !$this->isUserValid($mysqli))
                         {
                            $mysqli->close();
                            throw new Exception(ACCESS_TOKEN_INCORRECT);
                         }
                  
                          //get results
                          $result = $mysqli->query($query);
                          //check if there were now error in query. if so - throw an exception
                          if (!$result)
                          {
                              $mysqlError = $mysqli->error . __LINE__;
                              //close the connection
                              $mysqli->close();
                              throw new Exception ("mySQL Error: " . $mysqlError);
                          }
                          //fetch the results into an array
                          $rows = $result->fetch_all(MYSQLI_BOTH);
                          //close the connection
                          $result->close();
                          $result->free();
                          $mysqli->close();
                          //return the results if any
                          return $rows;
                      }
                  
                      /**
                       * Check if user is valid
                       * @param $mysqli mysqli connection to db
                       * @return true if user is valid, false otherwise
                       */
                      function isUserValid($mysqli)
                      {
                          //Check if there is a saved access token. if not - throw an exception
                          if (is_null($this->user) || $this->user->getPicoAccessToken() == null)
                            throw new Exception(ACCESS_TOKEN_INCORRECT);
                          //get user details
                          $facebookId = $this->user->getFacebookId();
                          $picoAccessToken = $this->user->getPicoAccessToken();
                          //create verification query
                          $verificationQuery = "Call isUserValid('$facebookId','$picoAccessToken')";
                          //execute query
                          $result = $mysqli->query($verificationQuery);
                  
                          //if query had error - throw exception
                          if (!$result)
                          {
                           $mysqlError = $mysqli->error . __LINE__;
                           //close the connection
                           $mysqli->close();
                           throw new Exception ("mySQL Error: " . $mysqlError);
                          }
                          $rows = $result->fetch_all(MYSQLI_ASSOC);
                          $rows = $rows[0];
                          $result->free_result();
                          //return user valid status
                          return isset($rows["isUserValid"]) && $rows["isUserValid"] == 1;
                      }
                  

                  推荐答案

                  每个存储过程至少返回两个结果

                  Every stored procedure returns at least two results

                  • 一个(或多个)实际结果
                  • 一个空的结果告诉客户没有更多的结果.

                  你必须使用 mysqli_more_results()/mysqli_next_result() 来清理它们.

                  You have to use mysqli_more_results()/mysqli_next_result() to clean them.

                  如果您的过程只返回一个结果,或者您只想要第一个结果之外的任何额外结果,您可以使用以下代码片段清理结果队列:

                  If your procedure returns only one result, or you just don't want any extra results but the first one, you can clean up the results queue with this code snippet:

                  while($mysqli->more_results())
                  {
                      $mysqli->next_result();
                      if($res = $mysqli->store_result())
                      {
                          $res->free(); 
                      }
                  }
                  

                  这篇关于PHP mysqli 命令不同步;你现在不能运行这个命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:MySQLi未找到错误 下一篇:MySql 性能慢

                  相关文章

                  最新文章

                • <small id='ML01P'></small><noframes id='ML01P'>

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

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