From 39b622db9bda38282a32bb45623da63efe685729 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 16 Jan 2008 21:10:09 +0000 Subject: Many new Active Record functions, and another whack of stuff --- system/database/DB_result.php | 50 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'system/database/DB_result.php') diff --git a/system/database/DB_result.php b/system/database/DB_result.php index b438ad1d8..36eddd840 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -34,6 +34,7 @@ class CI_DB_result { var $result_object = array(); var $current_row = 0; var $num_rows = 0; + var $row_data = NULL; /** @@ -118,16 +119,65 @@ class CI_DB_result { * Query result. Acts as a wrapper function for the following functions. * * @access public + * @param string * @param string can be "object" or "array" * @return mixed either a result object or array */ function row($n = 0, $type = 'object') { + if ( ! is_numeric($n)) + { + // We cache the row data for subsequent uses + if ( ! is_array($this->row_data)) + { + $this->row_data = $this->row_array(0); + } + + if (isset($this->row_data[$n])) + { + return $this->row_data[$n]; + } + // reset the $n variable if the result was not achieved + $n = 0; + } + return ($type == 'object') ? $this->row_object($n) : $this->row_array($n); } // -------------------------------------------------------------------- + /** + * Assigns an item into a particular column slot + * + * @access public + * @return object + */ + function set_row($key, $value = NULL) + { + // We cache the row data for subsequent uses + if ( ! is_array($this->row_data)) + { + $this->row_data = $this->row_array(0); + } + + if (is_array($key)) + { + foreach ($key as $k => $v) + { + $this->row_data[$k] = $v; + } + + return; + } + + if ($key != '' AND ! is_null($value)) + { + $this->row_data[$key] = $value; + } + } + + // -------------------------------------------------------------------- + /** * Returns a single result row - object version * -- cgit v1.2.3-24-g4f1b