admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 1 | <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); |
| 2 | /** |
| 3 | * Code Igniter |
| 4 | * |
| 5 | * An open source application development framework for PHP 4.3.2 or newer |
| 6 | * |
| 7 | * @package CodeIgniter |
| 8 | * @author Rick Ellis |
| 9 | * @copyright Copyright (c) 2006, pMachine, Inc. |
| 10 | * @license http://www.codeignitor.com/user_guide/license.html |
| 11 | * @link http://www.codeigniter.com |
| 12 | * @since Version 1.0 |
| 13 | * @filesource |
| 14 | */ |
| 15 | |
| 16 | // ------------------------------------------------------------------------ |
| 17 | |
| 18 | /** |
| 19 | * Database Result Class |
| 20 | * |
| 21 | * This is the platform-independent result class. |
| 22 | * This class will not be called directly. Rather, the adapter |
| 23 | * class for the specific database will extend and instantiate it. |
| 24 | * |
| 25 | * @category Database |
| 26 | * @author Rick Ellis |
| 27 | * @link http://www.codeigniter.com/user_guide/database/ |
| 28 | */ |
| 29 | class CI_DB_result { |
| 30 | |
| 31 | var $conn_id = FALSE; |
| 32 | var $result_id = FALSE; |
| 33 | var $db_debug = FALSE; |
| 34 | var $result_array = array(); |
| 35 | var $result_object = array(); |
| 36 | var $current_row = 0; |
| 37 | |
| 38 | /** |
| 39 | * Query result. Acts as a wrapper function for the following functions. |
| 40 | * |
| 41 | * @access public |
| 42 | * @param string can be "object" or "array" |
| 43 | * @return mixed either a result object or array |
| 44 | */ |
| 45 | function result($type = 'object') |
| 46 | { |
| 47 | return ($type == 'object') ? $this->result_object() : $this->result_array(); |
| 48 | } |
| 49 | |
| 50 | // -------------------------------------------------------------------- |
| 51 | |
| 52 | /** |
| 53 | * Query result. "object" version. |
| 54 | * |
| 55 | * @access public |
| 56 | * @return object |
| 57 | */ |
| 58 | function result_object() |
| 59 | { |
| 60 | if (count($this->result_object) > 0) |
| 61 | { |
| 62 | return $this->result_object; |
| 63 | } |
| 64 | |
| 65 | while ($row = $this->_fetch_object()) |
| 66 | { |
| 67 | $this->result_object[] = $row; |
| 68 | } |
| 69 | |
| 70 | if (count($this->result_object) == 0) |
| 71 | { |
| 72 | return FALSE; |
| 73 | } |
| 74 | |
| 75 | return $this->result_object; |
| 76 | } |
| 77 | |
| 78 | // -------------------------------------------------------------------- |
| 79 | |
| 80 | /** |
| 81 | * Query result. "array" version. |
| 82 | * |
| 83 | * @access public |
| 84 | * @return array |
| 85 | */ |
| 86 | function result_array() |
| 87 | { |
| 88 | if (count($this->result_array) > 0) |
| 89 | { |
| 90 | return $this->result_array; |
| 91 | } |
| 92 | |
| 93 | while ($row = $this->_fetch_assoc()) |
| 94 | { |
| 95 | $this->result_array[] = $row; |
| 96 | } |
| 97 | |
| 98 | if (count($this->result_array) == 0) |
| 99 | { |
| 100 | return FALSE; |
| 101 | } |
| 102 | |
| 103 | return $this->result_array; |
| 104 | } |
| 105 | |
| 106 | // -------------------------------------------------------------------- |
| 107 | |
| 108 | /** |
| 109 | * Query result. Acts as a wrapper function for the following functions. |
| 110 | * |
| 111 | * @access public |
| 112 | * @param string can be "object" or "array" |
| 113 | * @return mixed either a result object or array |
| 114 | */ |
| 115 | function row($n = 0, $type = 'object') |
| 116 | { |
| 117 | return ($type == 'object') ? $this->row_object($n) : $this->row_array($n); |
| 118 | } |
| 119 | |
| 120 | // -------------------------------------------------------------------- |
| 121 | |
| 122 | /** |
| 123 | * Returns a single result row - object version |
| 124 | * |
| 125 | * @access public |
| 126 | * @return object |
| 127 | */ |
| 128 | function row_object($n = 0) |
| 129 | { |
| 130 | if (FALSE === ($result = $this->result_object())) |
| 131 | { |
| 132 | return FALSE; |
| 133 | } |
| 134 | |
| 135 | if ($n != $this->current_row AND isset($result[$n])) |
| 136 | { |
| 137 | $this->current_row = $n; |
| 138 | } |
| 139 | |
| 140 | return $result[$this->current_row]; |
| 141 | } |
| 142 | |
| 143 | // -------------------------------------------------------------------- |
| 144 | |
| 145 | /** |
| 146 | * Returns a single result row - array version |
| 147 | * |
| 148 | * @access public |
| 149 | * @return array |
| 150 | */ |
| 151 | function row_array($n = 0) |
| 152 | { |
| 153 | if (FALSE === ($result = $this->result_array())) |
| 154 | { |
| 155 | return FALSE; |
| 156 | } |
| 157 | |
| 158 | if ($n != $this->current_row AND isset($result[$n])) |
| 159 | { |
| 160 | $this->current_row = $n; |
| 161 | } |
| 162 | |
| 163 | return $result[$this->current_row]; |
| 164 | } |
| 165 | |
| 166 | |
| 167 | // -------------------------------------------------------------------- |
| 168 | |
| 169 | /** |
| 170 | * Returns the "first" row |
| 171 | * |
| 172 | * @access public |
| 173 | * @return object |
| 174 | */ |
| 175 | function first_row($type = 'object') |
| 176 | { |
| 177 | if (FALSE === ($result = $this->result($type))) |
| 178 | { |
| 179 | return FALSE; |
| 180 | } |
| 181 | return $result[0]; |
| 182 | } |
| 183 | |
| 184 | // -------------------------------------------------------------------- |
| 185 | |
| 186 | /** |
| 187 | * Returns the "last" row |
| 188 | * |
| 189 | * @access public |
| 190 | * @return object |
| 191 | */ |
| 192 | function last_row($type = 'object') |
| 193 | { |
| 194 | if (FALSE === ($result = $this->result($type))) |
| 195 | { |
| 196 | return FALSE; |
| 197 | } |
| 198 | return $result[count($result) -1]; |
| 199 | } |
| 200 | |
| 201 | // -------------------------------------------------------------------- |
| 202 | |
| 203 | /** |
| 204 | * Returns the "next" row |
| 205 | * |
| 206 | * @access public |
| 207 | * @return object |
| 208 | */ |
| 209 | function next_row($type = 'object') |
| 210 | { |
| 211 | if (FALSE === ($result = $this->result($type))) |
| 212 | { |
| 213 | return FALSE; |
| 214 | } |
| 215 | |
| 216 | if (isset($result[$this->current_row + 1])) |
| 217 | { |
| 218 | ++$this->current_row; |
| 219 | } |
| 220 | |
| 221 | return $result[$this->current_row]; |
| 222 | } |
| 223 | |
| 224 | // -------------------------------------------------------------------- |
| 225 | |
| 226 | /** |
| 227 | * Returns the "previous" row |
| 228 | * |
| 229 | * @access public |
| 230 | * @return object |
| 231 | */ |
| 232 | function previous_row($type = 'object') |
| 233 | { |
| 234 | if (FALSE === ($result = $this->result($type))) |
| 235 | { |
| 236 | return FALSE; |
| 237 | } |
| 238 | |
| 239 | if (isset($result[$this->current_row - 1])) |
| 240 | { |
| 241 | --$this->current_row; |
| 242 | } |
| 243 | return $result[$this->current_row]; |
| 244 | } |
| 245 | |
| 246 | /** |
| 247 | * Number of rows in the result set |
| 248 | * |
| 249 | * @access public |
| 250 | * @return integer |
| 251 | */ |
| 252 | function num_rows() |
| 253 | { |
| 254 | // Result supplied by the result adaptor class |
| 255 | } |
| 256 | |
| 257 | // -------------------------------------------------------------------- |
| 258 | |
| 259 | /** |
| 260 | * Number of fields in the result set |
| 261 | * |
| 262 | * @access public |
| 263 | * @return integer |
| 264 | */ |
| 265 | function num_fields() |
| 266 | { |
| 267 | // Result supplied by the result adaptor class |
| 268 | } |
| 269 | |
| 270 | // -------------------------------------------------------------------- |
| 271 | |
| 272 | /** |
| 273 | * Field data |
| 274 | * |
| 275 | * Generates an array of objects containing field meta-data |
| 276 | * |
| 277 | * @access public |
| 278 | * @return array |
| 279 | */ |
| 280 | function field_data() |
| 281 | { |
| 282 | // Result supplied by the result adaptor class |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | ?> |