加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 扩展mysqli_result – 它是否使用store_result()或use_re

发布时间:2020-12-13 22:27:26 所属栏目:PHP教程 来源:网络整理
导读:我写了一个 mysqli的孩子,其中有一个返回mysqli_result子元素的查询方法.此结果子项将具有我的应用程序独有的其他方法. public MySQL extends mysqli{ public function query($query) { if ($this-real_query($query)) { if ($this-field_count 0) { return
我写了一个 mysqli的孩子,其中有一个返回mysqli_result子元素的查询方法.此结果子项将具有我的应用程序独有的其他方法.

public MySQL extends mysqli
{
    public function query($query)
    {
        if ($this->real_query($query)) {
            if ($this->field_count > 0) {
                return new MySQL_Result($this);
            }
            return true;
        }
        return false;
    }

}

class MySQL_Result extends mysqli_result
{
    public function fetch_objects() {
        $rows = array();
        while($row = $this->fetch_object())
            $rows[$row->id] = $row;
        return $rows;
    }
}

我无法弄清楚fetch_object()是否使用缓冲或未缓冲的SQL数据.

mysqli_result的构造函数在mysqli.php中不可见,所以我无法看到它是否调用$mysqli-> store_result()或$mysqli-> use_result().

我尝试将这些方法添加到MySQL,但两个函数都没有回应.

public function store_result($option='a') {
        echo "STORE RESULT<br/>";
    }

    public function use_result($option='a') {
        echo "USE RESULT<br/>";
    }

这是否意味着mysqli_result构造函数不会调用?如果是这样,在调用fetch_object时如何访问SQL数据?

…………….

我想要缓冲的SQL数据.如果我无法弄清楚子构造函数在做什么,我可能必须用调用$mysqli-> store_result()的装饰器替换结果子类.

我是PHP / OOP的新手,非常感谢反馈.谢谢.

解决方法

mysqli_result uses buffered results from MySQL(强调我的)

Queries are using the buffered mode by default. This means that query results are immediately transferred from the MySQL Server to PHP and then are kept in the memory of the PHP process. This allows additional operations like counting the number of rows,and moving (seeking) the current result pointer. It also allows issuing further queries on the same connection while working on the result set. The downside of the buffered mode is that larger result sets might require quite a lot memory. The memory will be kept occupied till all references to the result set are unset or the result set was explicitly freed,which will automatically happen during request end the latest. The terminology “store result” is also used for buffered mode,as the whole result set is stored at once.

过程就是这样

>您执行查询. MySQL发回结果
> mysqli_query和mysqli_get_result(预编译语句)会将此数据集加载到mysqli_result对象中

实际上,您必须不遗余力地执行异步查询

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读