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

我写了一个 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对象中

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

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...