From e21847e5304a2b173a6ac96fb4f74d4c9d82df82 Mon Sep 17 00:00:00 2001 From: skodak Date: Sat, 25 Oct 2008 18:12:17 +0000 Subject: [PATCH] MDL-14679 dml/native_mysqli fixed recordsets handling --- lib/dml/mysqli_native_moodle_recordset.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/dml/mysqli_native_moodle_recordset.php b/lib/dml/mysqli_native_moodle_recordset.php index fd9ff7ea2c2..98baa8592f6 100644 --- a/lib/dml/mysqli_native_moodle_recordset.php +++ b/lib/dml/mysqli_native_moodle_recordset.php @@ -6,12 +6,10 @@ class mysqli_native_moodle_recordset extends moodle_recordset { protected $result; protected $current; - protected $row; public function __construct($result) { $this->result = $result; $this->current = $this->fetch_next(); - $this->row = 0; } public function __destruct() { @@ -21,24 +19,25 @@ class mysqli_native_moodle_recordset extends moodle_recordset { private function fetch_next() { if ($row = $this->result->fetch_assoc()) { $row = array_change_key_case($row, CASE_LOWER); - $row = (object)$row; } return $row; } public function current() { - return $this->current; + return is_null($this->current) ? null : (object)$this->current; } public function key() { - return $this->row; + /// return first column value as key + if (is_null($this->current)) { + return false; + } + $key = reset($this->current); + return $key; } public function next() { - if ($this->current = $this->fetch_next()) { - $this->row++; - } - return $this->current; + $this->current = $this->fetch_next(); } public function rewind() { @@ -55,6 +54,5 @@ class mysqli_native_moodle_recordset extends moodle_recordset { $this->result = null; } $this->current = null; - $this->row = 0; } }