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

      获取带有 mysqli 结果的行数组

      时间:2023-07-31

        <small id='7HBE8'></small><noframes id='7HBE8'>

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

                本文介绍了获取带有 mysqli 结果的行数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我需要从结果对象中获取所有行.我正在尝试构建一个包含所有行的新数组.

                I need to get all the rows from result object. I’m trying to build a new array that will hold all rows.

                这是我的代码:

                $sql = new mysqli($config['host'],$config['user'],$config['pass'],$config['db_name']);
                if (mysqli_connect_errno())
                {
                    printf("Connect failed: %s
                ", mysqli_connect_error());
                    exit();
                }
                $query = "SELECT domain FROM services";
                $result = $sql->query($query);           
                while($row = $result->fetch_row());
                {
                    $rows[]=$row;
                }
                $result->close();
                $sql->close();
                return $rows;
                

                $rows 应该是包含所有行的新数组,但我得到了一个空数组.

                $rows is supposed to be the new array that contains all, rows but instead I get an empty array.

                知道为什么会这样吗?

                推荐答案

                你有一个轻微的语法问题,即一个错误的分号.

                You had a slight syntax problem, namely an errant semi-colon.

                while($row = $result->fetch_row());
                

                注意到末尾的分号了吗?这意味着后面的块没有在循环中执行.摆脱它,它应该可以工作.

                Notice the semi-colon at the end? It means the block following wasn't executed in a loop. Get rid of that and it should work.

                另外,你可能想让mysqli报告它遇到的所有问题:

                Also, you may want to ask mysqli to report all problems it encountered:

                mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
                $sql = new mysqli($config['host'], $config['user'], $config['pass'], $config['db_name']);
                
                $query = "SELECT domain FROM services";
                $result = $sql->query($query);
                $rows = [];
                while($row = $result->fetch_row()) {
                    $rows[] = $row;
                }
                return $rows;
                

                这篇关于获取带有 mysqli 结果的行数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:调用非对象 PHP 帮助上的成员函数 prepare() 下一篇:MySQLi 查询只返回一行

                相关文章

                最新文章

                  <tfoot id='2xnhE'></tfoot>
                  <legend id='2xnhE'><style id='2xnhE'><dir id='2xnhE'><q id='2xnhE'></q></dir></style></legend>

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

                  • <bdo id='2xnhE'></bdo><ul id='2xnhE'></ul>
                2. <small id='2xnhE'></small><noframes id='2xnhE'>