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

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

    <legend id='PylYQ'><style id='PylYQ'><dir id='PylYQ'><q id='PylYQ'></q></dir></style></legend>
      <bdo id='PylYQ'></bdo><ul id='PylYQ'></ul>

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

        在 &lt;path&gt; 中的 boolean 上调用成员函数

        时间:2023-07-31
      1. <small id='R9TlY'></small><noframes id='R9TlY'>

          <bdo id='R9TlY'></bdo><ul id='R9TlY'></ul>
          <legend id='R9TlY'><style id='R9TlY'><dir id='R9TlY'><q id='R9TlY'></q></dir></style></legend>

            1. <tfoot id='R9TlY'></tfoot>
                <tbody id='R9TlY'></tbody>
                • <i id='R9TlY'><tr id='R9TlY'><dt id='R9TlY'><q id='R9TlY'><span id='R9TlY'><b id='R9TlY'><form id='R9TlY'><ins id='R9TlY'></ins><ul id='R9TlY'></ul><sub id='R9TlY'></sub></form><legend id='R9TlY'></legend><bdo id='R9TlY'><pre id='R9TlY'><center id='R9TlY'></center></pre></bdo></b><th id='R9TlY'></th></span></q></dt></tr></i><div id='R9TlY'><tfoot id='R9TlY'></tfoot><dl id='R9TlY'><fieldset id='R9TlY'></fieldset></dl></div>
                  本文介绍了在 &lt;path&gt; 中的 boolean 上调用成员函数 fetch_assoc()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我在运行以下代码以显示从数据库进行的预订时遇到上述错误.

                  I'm getting the above error when running the below code to display bookings made from a database.

                  <?php
                          
                          $servername = "localhost";
                          $username = "*********";
                          $password = "********";
                          $dbname = "thelibr1_fyp";
                  
                  
                          // Create connection
                          $conn = new mysqli($servername, $username, $password, $dbname);
                          // Check connection
                          if ($conn->connect_error) {
                              die("Connection failed: " . $conn->connect_error);
                          } 
                          
                          $sql = "SELECT id, tablename, numseats, person FROM confirms";
                          $result = $conn->query($sql);
                          ?>
                                          
                          <table id="Confirms" border ="2" style="length:900px;width:350px;">
                                <thead>
                                  <tr style= "background-color: #A4A4A4;">
                                    <td>Booking ID:</td>
                                    <td>Table No.:</td>
                                    <td>No. of Seats:</td>
                                    <td>Person:</td>
                                  </tr>
                                </thead>
                              <tbody>
                                  <?php
                                    while(($row = $result->fetch_assoc()) !== null){
                                      echo
                                      "<tr>
                                        <td>{$row['id']}</td>
                                        <td>{$row['tablename']}</td>
                                        <td>{$row['numseats']}</td>
                                        <td>{$row['person']}</td>
                                      </tr>
                  ";
                                    }
                                  ?>
                              </tbody>
                          </table>
                  

                  当我开始实时托管它时,我才开始收到错误消息.它在我的个人电脑上运行良好,数据库连接也运行良好.

                  I only started to receive the error when i started hosting it live. It works fine on my personal computer, the databse connection works fine also.

                  推荐答案

                  query 方法可以返回 false 而不是结果集,以防出现错误.这就是为什么您会在 fetch_assoc 方法调用中出现错误的原因,当 $resultfalse 时,这显然不存在.

                  The query method can return false instead of a result set in case there is an error. That is why you get the error on the fetch_assoc method call, which obviously does not exist when $result is false.

                  这意味着您的 SELECT 语句有错误.要显示该错误,请执行以下操作:

                  This means you have an error in your SELECT statement. To get that error displayed, do this:

                   $result = $conn->query($sql) or die($conn->error);
                  

                  很可能您对表名或列名的拼写有误.可能在移动到主机时您没有正确创建该表,并在那里拼写错误.

                  Most probably you have a wrong spelling for the table name or a column name. Maybe when moving to the host you did not create that table correctly, and made a spelling mistake there.

                  实际上,当您通过 phpAdmin 执行相同的查询时,您应该会看到相同的错误.

                  You should in fact see the same error when executing the same query via phpAdmin.

                  另外,替换这一行:

                  while(($row = $result->fetch_assoc()) !== null){
                  

                  只要:

                  while($row = $result->fetch_assoc()) {
                  

                  你也可以添加这个用于调试:

                  You could also add this for debugging:

                  echo "number of rows: " . $result->num_rows;
                  

                  这篇关于在 &lt;path&gt; 中的 boolean 上调用成员函数 fetch_assoc()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:使用准备好的语句时是否需要 mysql_real_escape_str 下一篇:如何在 PHP 中使用 mysqli_query()?

                  相关文章

                  最新文章

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

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

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