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

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

<legend id='7iAeE'><style id='7iAeE'><dir id='7iAeE'><q id='7iAeE'></q></dir></style></legend>
    <tfoot id='7iAeE'></tfoot>

      • <bdo id='7iAeE'></bdo><ul id='7iAeE'></ul>

    1. 调用未定义的函数 mysqli_result::num_rows()

      时间:2023-07-31
    2. <tfoot id='buyM8'></tfoot>

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

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

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

                  <tbody id='buyM8'></tbody>
                本文介绍了调用未定义的函数 mysqli_result::num_rows()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我正在尝试计算结果中的行数,但不断收到上述返回的错误.我已经检查了手册,我正在使用 mysqli_result::num_rows() ,因为我应该使用(我使用的是面向对象的风格.)我在这里工作了三个类.

                I'm trying to count the number of rows in a result, and I keep getting the above returned error. I've checked the manual, and I'm using mysqli_result::num_rows() as I should be (I'm using object oriented style.) I've got three classes working here.

                类(连接):

                class utils_MysqlImprovedConnection {
                    protected $_connection;
                
                    public function __construct($host, $user, $pwd, $db)
                    {
                        $this->_connection = @new mysqli($host, $user, $pwd, $db);
                        if(mysqli_connect_errno ()) {
                            throw new RuntimeException('Cannot access database:' . mysqli_connect_error());
                        }
                    }
                
                    public function getResultSet($sql)
                    {
                        $results = new utils_MysqlImprovedResult($sql, $this->_connection);
                        return $results;
                    }
                
                    public function  __destruct() {
                        $this->_connection;
                    }
                }
                

                类(处理结果):

                class utils_MysqlImprovedResult implements Iterator, Countable {
                    protected $_key;
                    protected $_current;
                    protected $_valid;
                    protected $_result;
                
                
                    public function  __construct($sql, $connection) {
                       if (!$this->_result = $connection->query($sql)){
                           throw new RuntimeException($connection->error . '. The actual query submitted was: '. $sql);
                       }
                    }
                
                    public function  rewind()
                    {
                        if (!is_null($this->_key)){
                            $this->_result->data_seek(0);
                        }
                        $this->_current = $this->_result->fetch_assoc();
                        $this->_valid = is_null($this->_current) ? false : true;
                    }
                    public function valid()
                    {
                        return $this->_valid;
                    }
                    public function current()
                    {
                        return $this->_current;
                    }
                    public function key()
                    {
                        return $this->_key;
                    }
                    public function next()
                    {
                        $this->_current = $this->_result->fetch_assoc();
                        $this->_valid = is_null($this->_current) ? false : true;
                        $this->_key++;
                    }
                    public function count()
                    {
                        $this->_result->store_result();
                        $this->_result->num_rows();
                    }
                }
                

                类函数:

                public function resetPassword($email, $pass){
                    //check if email exists, update authkey and password, send email
                    $sql = "SELECT * FROM table WHERE column = '$email'";
                    $results = $this->_db->getResultSet($sql);
                    if($results->count() == 1){
                        // Process
                        $this->_message = "Success!";
                        return $this->_message;
                    } else {
                        // Not unique
                        $this->_error = "Try again";
                       return $this->_error;
                    } 
                }
                

                我用来调用所有这些的测试页面是(包含语句只是工作正常的 __autoload() 函数):

                The test page I'm using to call all this is (include statement is just __autoload() function that is working fine):

                $columnvar = 'emailaddress@test.com';
                $pass = 'blah';
                require_once 'inc.init.php';
                $user = new utils_User();
                try{
                   $string = $user->resetPassword($email, $pass);
                   echo $string;
                }
                catch(Exception $e) {
                   echo $e;
                }
                

                推荐答案

                从手册上看,mysqli_result::num_rows 不是一个函数,而是一个包含行数的变量.

                From the manual, it seems that mysqli_result::num_rows isn't a function, but rather a variable containing the number of rows.

                可以这样使用:

                $num_rows = $mysqli_result->num_rows;
                

                等价的函数是mysqli_num_rows($result),你在其中传入mysqli_result对象,但前提是你使用的是过程风格而不是面向对象风格.

                The function equivalent is mysqli_num_rows($result), where you pass in the mysqli_result object, but that's if you're using the procedural style rather than object oriented style.

                在您的代码中,您应该将 utils_MysqlImprovedResult 类中的 count() 函数更改为如下所示(我假设这是您获得的函数)错误信息),

                In your code, you should change your count() function in the utils_MysqlImprovedResult class to be like this (I'm assuming that's the function where you're getting the error message),

                public function count()
                {
                    // Any other processing you want
                    // ...
                    return $this->_result->num_rows;
                }
                

                或者如果你想混合 OO 和程序风格(可能是个坏主意),

                or alternatively if you want to mix OO and procedural styles (probably a bad idea),

                public function count()
                {
                    // Any other processing you want
                    // ...
                    return mysqli_num_rows($this->_result);
                }
                

                这篇关于调用未定义的函数 mysqli_result::num_rows()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:PHP 准备好的语句问题 下一篇:mysql 中的 store_result() 和 get_result() 返回 false

                相关文章

                最新文章

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

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

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