我寫的mysqli的孩子返回mysqli_result的子查詢方法。這個結果孩子將有其他獨特的方法,我的應用程序。擴展mysqli_result - 是否使用store_result()或use_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
構造不調用要麼?如果是這樣,它是如何訪問SQL數據時fetch_object
叫?
................
我想緩衝的SQL數據。如果我不能找出孩子的構造函數是幹什麼的,我可能與調用$mysqli->store_result()
一個裝飾來替代結果子類。
我是新來的PHP/OOP和非常感激反饋。謝謝。
除了我重載了MySQL中的「查詢」方法並調用real_query()。所以沒有從SQL返回。返回必須發生在mysqli_result構造函數或fetch_object()中。 – Nick