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

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

    <tfoot id='FeVNj'></tfoot>

      1. PDO 无缓冲查询

        时间:2023-09-20

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

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

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

                <tfoot id='kRESL'></tfoot>

                  本文介绍了PDO 无缓冲查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试了解 PDO 的详细信息.所以我编码了这个:

                  I'm trying to get into PDO details. So I coded this:

                  $cn = getConnection();
                  
                  // get table sequence
                  $comando = "call p_generate_seq('bitacora')";
                  $id = getValue($cn, $comando);
                  
                  //$comando = 'INSERT INTO dsa_bitacora (id, estado, fch_creacion) VALUES (?, ?, ?)';
                  $comando = 'INSERT INTO dsa_bitacora (id, estado, fch_creacion) VALUES (:id, :estado, :fch_creacion)';
                  $parametros = array (
                      ':id'=> (int)$id,
                      ':estado'=>1,
                      ':fch_creacion'=>date('Y-m-d H:i:s')
                  );
                  execWithParameters($cn, $comando, $parametros);
                  

                  我的 getValue 函数工作正常,我得到了表的下一个序列.但是当我进入 execWithParameters 时,我得到了这个异常:

                  my getValue function works fine, and I get the next sequence for the table. But when I get into execWithParameters, i get this exception:

                  PDOException:SQLSTATE[HY000]:一般错误:2014 无法执行查询,而其他未缓冲的查询处于活动状态.考虑使用 PDOStatement::fetchAll().或者,如果您的代码只针对 mysql 运行,您可以通过设置 PDO::MYSQL_ATTR_USE_BUFFERED_QUERY 属性来启用查询缓冲.在 D:Servidorxampp_1_7_1htdocsitacorafunc_db.php 第 77 行

                  PDOException: SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute. in D:Servidorxampp_1_7_1htdocsitacorafunc_db.php on line 77

                  我试图修改连接属性,但它不起作用.

                  I tried to modify the connection attributes but it doesn't work.

                  这些是我的核心数据库函数:

                  These are my core db functions:

                  function getConnection() {
                      try {
                          $cn = new PDO("mysql:host=$host;dbname=$bd", $usuario, $clave, array(
                                  PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
                              ));
                  
                          $cn->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
                          return $cn;
                      } catch (PDOException $e) {
                          print "Error!: " . $e->getMessage() . "<br/>";
                          die();
                      }
                  }
                  function getValue($cn, $comando) {
                      $resul = $cn->query($comando);
                          if (!$resul) return null;
                          while($res = $resul->fetch()) {
                              $retorno = $res[0][0];
                              break;
                          }
                          return $retorno;
                  }
                  function execWithParameters($cn, $comando, $parametros) {
                      $q = $cn->prepare($comando);
                      $q->execute($parametros);
                      if ($q->errorInfo() != null) {
                          $e = $q->errorInfo();
                          echo $e[0].':'.$e[1].':'.$e[2];
                      }
                  }
                  

                  有人可以为此提供帮助吗?PD.请不要建议做 autonumeric id,因为我是从另一个系统移植的.

                  Somebody who can shed a light for this? PD. Please do not suggest doing autonumeric id, cause i am porting from another system.

                  推荐答案

                  问题是 mysql 在给定时间只允许一个未完成的游标.通过使用 fetch() 方法而不消耗所有挂起的数据,您将保持游标打开.

                  The issue is that mysql only allows for one outstanding cursor at a given time. By using the fetch() method and not consuming all the pending data, you are leaving a cursor open.

                  推荐的方法是使用 fetchAll() 方法消耗所有数据.另一种方法是使用 closeCursor() 方法.

                  The recommended approach is to consume all the data using the fetchAll() method. An alternative is to use the closeCursor() method.

                  如果你改变这个功能,我想你会更开心:

                  If you change this function, I think you will be happier:

                  <?php
                  function getValue($cn, $comando) {
                      $resul = $cn->query($comando);
                      if (!$resul) return null;
                      foreach ($resul->fetchAll() as $res) {
                              $retorno = $res[0];
                              break;
                      }
                      return $retorno;
                  }
                  ?>
                  

                  这篇关于PDO 无缓冲查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:PDO lastInsertId() 总是返回 0 下一篇:PDO->query() 和 PDO->exec() 之间的区别

                  相关文章

                  最新文章

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

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

                    <tfoot id='wDk7U'></tfoot>
                    <legend id='wDk7U'><style id='wDk7U'><dir id='wDk7U'><q id='wDk7U'></q></dir></style></legend>