【发布时间】:2016-12-25 19:02:34
【问题描述】:
我用一个返回mysqli_result 子项的查询方法编写了一个mysqli 子项。此结果子项将具有我的应用独有的其他方法。
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() 的装饰器。
【问题讨论】: