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

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

        <tfoot id='jTG7W'></tfoot>
          <bdo id='jTG7W'></bdo><ul id='jTG7W'></ul>

        警告:mysqli_query() 期望参数 1 是 mysqli,在

        时间:2023-07-31

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

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

                  <legend id='lbSgr'><style id='lbSgr'><dir id='lbSgr'><q id='lbSgr'></q></dir></style></legend>
                  本文介绍了警告:mysqli_query() 期望参数 1 是 mysqli,在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试构建一个简单的自定义 CMS,但出现错误:

                  I am trying to build a simple custom CMS, but I'm getting an error:

                  警告:mysqli_query() 期望参数 1 是 MySQLi,在

                  Warning: mysqli_query() expects parameter 1 to be MySQLi, null given in

                  为什么我会收到这个错误?我所有的代码都已经是 MySQLi 并且我使用了两个参数,而不是一个.

                  Why am I getting this error? All my code is already MySQLi and I am using two parameters, not one.

                  $con=mysqli_connect("localhost","xxxx","xxxx","xxxxx");
                  
                  //check connection
                  if (mysqli_connect_errno($con))
                  {
                      echo "Failed to connect to MySQL:" . mysqli_connect_error();
                  }
                  
                  function getPosts() {
                      $query = mysqli_query($con,"SELECT * FROM Blog");
                      while($row = mysqli_fetch_array($query))
                      {
                          echo "<div class="blogsnippet">";
                          echo "<h4>" . $row['Title'] . "</h4>" . $row['SubHeading'];
                          echo "</div>";
                      }
                  }
                  

                  推荐答案

                  正如评论中提到的,这是一个范围界定问题.具体来说,$con 不在您的 getPosts 函数范围内.

                  As mentioned in comments, this is a scoping issue. Specifically, $con is not in scope within your getPosts function.

                  您应该将连接对象作为依赖项传入,例如

                  You should pass your connection object in as a dependency, eg

                  function getPosts(mysqli $con) {
                      // etc
                  

                  如果您的连接失败或发生错误,我也强烈建议您停止执行.这样的东西就足够了

                  I would also highly recommend halting execution if your connection fails or if errors occur. Something like this should suffice

                  mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); // throw exceptions
                  $con=mysqli_connect("localhost","xxxx","xxxx","xxxxx");
                  
                  getPosts($con);
                  

                  这篇关于警告:mysqli_query() 期望参数 1 是 mysqli,在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Mysqli更新抛出调用成员函数bind_param()错误 下一篇:致命错误:在非对象上调用成员函数 fetch_assoc()

                  相关文章

                  最新文章

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

                  <tfoot id='omFrH'></tfoot>

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