diff --git a/src/Db/Connection.php b/src/Db/Connection.php index 61b2e07..90eaf49 100644 --- a/src/Db/Connection.php +++ b/src/Db/Connection.php @@ -1,5 +1,4 @@ error = odbc_errormsg(Connection::get()); - } else { - try { - $this->results = array(); - $this->num_fields = odbc_num_fields($odbc_result); - $this->num_rows = odbc_num_rows($odbc_result); - - if ($this->num_fields > 0) { - while ($row = odbc_fetch_row($odbc_result)) { - $data = array(); - for ($i = 1; $i <= $this->num_fields; ++$i) { - $data[odbc_field_name($odbc_result, $i)] = utf8_encode(odbc_result($odbc_result, $i)); - } - $this->results[] = $data; - } - }; - } catch (\Exception $e) { - print($e->getMessage()); - } - - $this->cursor_index = 0; - $this->length = count($this->results); - odbc_free_result($odbc_result); - } - } - - public function get_num_rows() - { - return $this->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); - } -} diff --git a/src/Db/OdbcResultset.php b/src/Db/OdbcResultset.php new file mode 100644 index 0000000..586e946 --- /dev/null +++ b/src/Db/OdbcResultset.php @@ -0,0 +1,138 @@ +error = odbc_errormsg(Connection::get()); + } else { + try { + $this->results = array(); + $this->num_fields = odbc_num_fields($odbc_result); + $this->num_rows = odbc_num_rows($odbc_result); + + if ($this->num_fields > 0) { + while ($row = odbc_fetch_row($odbc_result)) { + $data = array(); + for ($i = 1; $i <= $this->num_fields; ++$i) { + $data[odbc_field_name($odbc_result, $i)] = utf8_encode(odbc_result($odbc_result, $i)); + } + $this->results[] = $data; + } + }; + } catch (\Exception $e) { + print($e->getMessage()); + } + + $this->cursor_index = 0; + $this->length = count($this->results); + odbc_free_result($odbc_result); + } + } + + public function get_num_rows() + { + return $this->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); + } +}