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

  • <tfoot id='D7TaY'></tfoot>

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

      <legend id='D7TaY'><style id='D7TaY'><dir id='D7TaY'><q id='D7TaY'></q></dir></style></legend>

      1. PDO 错误 - PDOException' 带有消息 'SQLSTATE[HY0

        时间:2023-10-05

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

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

              • <bdo id='Omrqn'></bdo><ul id='Omrqn'></ul>
                • <i id='Omrqn'><tr id='Omrqn'><dt id='Omrqn'><q id='Omrqn'><span id='Omrqn'><b id='Omrqn'><form id='Omrqn'><ins id='Omrqn'></ins><ul id='Omrqn'></ul><sub id='Omrqn'></sub></form><legend id='Omrqn'></legend><bdo id='Omrqn'><pre id='Omrqn'><center id='Omrqn'></center></pre></bdo></b><th id='Omrqn'></th></span></q></dt></tr></i><div id='Omrqn'><tfoot id='Omrqn'></tfoot><dl id='Omrqn'><fieldset id='Omrqn'></fieldset></dl></div>
                    <tbody id='Omrqn'></tbody>
                  本文介绍了PDO 错误 - PDOException' 带有消息 'SQLSTATE[HY000]: 一般错误'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我收到此错误:

                  Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error' in ...
                  

                  ...每当我使用 PDO 执行此代码时:

                  ..whenever I execute this code with PDO:

                  //Select data from the topic.
                  $s = $dbh->prepare("SELECT * FROM forum_topics WHERE forum_id=:forum_cat_id AND topic_id=:topicid");
                  $s->bindParam(':forum_cat_id', $forum_cat_id);
                  $s->bindParam(':topicid', $topicid);
                  $s->execute();
                  $f = $s->fetch();
                  
                  $s = $dbh->prepare("UPDATE forum_cats 
                      SET 
                          forum_last_postid = :last_post_id, forum_last_posttime = :time, 
                          forum_last_userid = :userid, forum_last_username = :username, 
                          forum_posts=forum_posts+1 
                      WHERE forum_id = :forum_cat_id");
                  $s->bindParam(':last_post_id', $last_post_id);
                  $s->bindParam(':time', $time);
                  $s->bindParam(':userid', $userid);
                  $s->bindParam(':username', $userdata['username']);
                  $s->bindParam(':forum_cat_id', $forum_cat_id);
                  try {
                      $s->execute();
                  }
                  catch(PDOException $e) {
                      die($e->getMessage());
                  }
                  
                  if (count($s->fetchAll()) == 0) {
                      return 3;
                  }
                  

                  我不知道为什么会这样.我已经检查了查询,但我根本找不到任何错误..

                  I have no idea why this is happening. I've checked the query, and I simply cant find any errors..

                  推荐答案

                  事情是这样的:

                  • 您正在尝试获取 UPDATE 查询.您不能这样做,因为 UPDATE 查询不返回值.如果您想知道查询影响了多少行,请改用 rowCount() 函数.请注意,并非所有数据库驱动程序都提供受影响的行.

                  • You are trying to fetch an UPDATE query. You can't do that because UPDATE queries does not return values. If you wish to know how many rows were affected by the query, use the rowCount() function instead. Notice that not all DB Drivers provide the affected rows.

                  您正在使用未声明的变量(至少在您在这里发布的代码中).这不是此特定错误的原因,但可能会产生其他错误.

                  You are using undeclared variables (at least in the code you posted here). This isn't the reason for this particular error, but could generate others.

                  您没有使用从数据库中选择的数据

                  You're not using the data you have selected from the database

                  另外,建议在try块内进行所有PDO操作,否则可能会得到未处理的异常.

                  Also, it is recommended to make all PDO operations within the try block, otherwise you may get unhandled exceptions.

                  这篇关于PDO 错误 - PDOException' 带有消息 'SQLSTATE[HY000]: 一般错误'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:PHP 运行查询所需的时间是 MySQL 客户端的 90 倍 下一篇:PHP PDO 获取对象

                  相关文章

                  最新文章

                • <tfoot id='eWBxm'></tfoot>

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

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