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

        • <bdo id='qxBoV'></bdo><ul id='qxBoV'></ul>
      1. 在布尔值上调用成员函数 fetch()

        时间:2023-09-21
        <legend id='u2Of6'><style id='u2Of6'><dir id='u2Of6'><q id='u2Of6'></q></dir></style></legend>
      2. <i id='u2Of6'><tr id='u2Of6'><dt id='u2Of6'><q id='u2Of6'><span id='u2Of6'><b id='u2Of6'><form id='u2Of6'><ins id='u2Of6'></ins><ul id='u2Of6'></ul><sub id='u2Of6'></sub></form><legend id='u2Of6'></legend><bdo id='u2Of6'><pre id='u2Of6'><center id='u2Of6'></center></pre></bdo></b><th id='u2Of6'></th></span></q></dt></tr></i><div id='u2Of6'><tfoot id='u2Of6'></tfoot><dl id='u2Of6'><fieldset id='u2Of6'></fieldset></dl></div>
      3. <small id='u2Of6'></small><noframes id='u2Of6'>

          1. <tfoot id='u2Of6'></tfoot>
              <tbody id='u2Of6'></tbody>

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

                • 本文介绍了在布尔值上调用成员函数 fetch()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我收到此错误:

                  致命错误:在布尔值上调用成员函数 fetch()C:xampphtdocs epogeneratormodeldatabase.php 第 34 行

                  Fatal error: Call to a member function fetch() on boolean in C:xampphtdocs epogeneratormodeldatabase.php on line 34

                  当我运行此代码时:

                      class database
                      {
                          private $user = 'root';
                          private $pass = '';
                          public $pdo;
                  
                          public function connect() {
                              try {
                                  $this->pdo = new PDO('mysql:host=localhost; dbname=generatordatabase', $this->user, $this->pass);
                                  echo 'Połączenie nawiązane!';
                              }
                              catch(PDOException $e) {
                                  echo 'Połączenie nie mogło zostać utworzone: ' . $e->getMessage();
                              }
                          }
                  
                          public function createTable() {
                  
                                          $q = $this->pdo -> query('SELECT * FROM article');
                                            while($row = $q->fetch()) {
                                                echo $row['id'].' ';
                                            }
                                            $q->closeCursor();
                          }
                      }
                  
                      ?>
                  

                  推荐答案

                  根据 PHP 手册 PDO::查询

                  PDO::query() 返回一个 PDOStatement 对象,或者失败时返回 FALSE.

                  PDO::query() returns a PDOStatement object, or FALSE on failure.

                  看起来您的查询失败(在第 33 行)并因此返回 BOOLEAN (false),可能是因为在执行时,PDO 尚未连接到包含名为 article.在 connect() 方法中,我看到它尝试连接到名为generatordatabase"的数据库;确保在调用 createTable() 之前建立此连接,否则确保它包含一个名为article"的表.

                  It looks like your query is failing (on line 33) and thus returning a BOOLEAN (false), likely because at that point in execution, PDO has not connected to a database that contains a table called article. In the connect() method I see that it tries to connect to a db called 'generatordatabase'; ensure this connection is being made prior to calling createTable(), otherwise ensure that it contains a table called 'article'.

                  我建议添加更多代码示例,例如在触发错误之前调用此类/方法的代码.

                  I would recommend adding some more code examples, for instance the code that calls this class/method before the error is triggered.

                  这篇关于在布尔值上调用成员函数 fetch()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

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

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

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

                      <tbody id='D6zB8'></tbody>

                          <tfoot id='D6zB8'></tfoot>