results = $resultset; $this->num_fields = is_array(current($resultset)) ? count(current($resultset)) : count($resultset); $this->num_rows = count($this->results); $this->length = $this->num_rows; $this->cursor_index = 0; } public function get_num_rows() { return $this->num_rows; } public function count() { return $this->get_num_rows(); } public function is_error() { return ($this->error ? true : false); } public function get_error() { return $this->error; } public function get_row() { return $this->current(); } public function to_array() { return $this->results; } // ArrayAccess /** * @param int $offset * @return bool */ public function offsetExists($offset) { return !$this->error && $this->cursor_index < $this->length && $this->cursor_index >= 0; } /** * @param int $offset * @return bool|array */ public function offsetGet($offset) { return $this->offsetExists($offset) ? $this->results[$offset] : false; } public function offsetSet($offset, $value) { if($this->offsetExists($offset)) { $this->results[$offset] = $value; } } public function offsetUnset($offset) { throw new \RuntimeException("This makes no sense at all."); } // Iterator /** * @return bool|array */ public function current() { return $this->offsetGet($this->cursor_index); } /** * @return int */ public function key() { return $this->cursor_index; } /** * @return array|bool */ public function next() { $current = $this->current(); ++$this->cursor_index; return $current; } public function rewind() { $this->cursor_index = 0; } /** * @return bool */ public function valid() { return $this->offsetExists($this->cursor_index); } }