blob: b3dbc21497903b2606842da8a1d63e171956f20a [file] [log] [blame]
admin7b613c72006-09-24 18:05:17 +00001<?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 */
29class CI_DB_result {
30
31 var $conn_id = FALSE;
32 var $result_id = FALSE;
admin7b613c72006-09-24 18:05:17 +000033 var $result_array = array();
34 var $result_object = array();
35 var $current_row = 0;
adminaf644692006-10-05 04:22:41 +000036 var $num_rows = 0;
admin7b613c72006-09-24 18:05:17 +000037
admine1063182006-09-25 22:12:16 +000038
admin7b613c72006-09-24 18:05:17 +000039 /**
40 * Query result. Acts as a wrapper function for the following functions.
41 *
42 * @access public
43 * @param string can be "object" or "array"
44 * @return mixed either a result object or array
45 */
46 function result($type = 'object')
adminaf644692006-10-05 04:22:41 +000047 {
admin7b613c72006-09-24 18:05:17 +000048 return ($type == 'object') ? $this->result_object() : $this->result_array();
49 }
admine1063182006-09-25 22:12:16 +000050
admin7b613c72006-09-24 18:05:17 +000051 // --------------------------------------------------------------------
52
53 /**
54 * Query result. "object" version.
55 *
56 * @access public
57 * @return object
58 */
59 function result_object()
60 {
61 if (count($this->result_object) > 0)
62 {
63 return $this->result_object;
64 }
adminaf644692006-10-05 04:22:41 +000065
66 $this->_data_seek(0);
admin7b613c72006-09-24 18:05:17 +000067 while ($row = $this->_fetch_object())
adminaf644692006-10-05 04:22:41 +000068 {
admin7b613c72006-09-24 18:05:17 +000069 $this->result_object[] = $row;
70 }
71
admin7b613c72006-09-24 18:05:17 +000072 return $this->result_object;
73 }
adminaf644692006-10-05 04:22:41 +000074
admin7b613c72006-09-24 18:05:17 +000075 // --------------------------------------------------------------------
76
77 /**
78 * Query result. "array" version.
79 *
80 * @access public
81 * @return array
82 */
83 function result_array()
84 {
85 if (count($this->result_array) > 0)
86 {
87 return $this->result_array;
88 }
adminaf644692006-10-05 04:22:41 +000089
90 $this->_data_seek(0);
admin7b613c72006-09-24 18:05:17 +000091 while ($row = $this->_fetch_assoc())
92 {
93 $this->result_array[] = $row;
94 }
95
admin7b613c72006-09-24 18:05:17 +000096 return $this->result_array;
97 }
98
99 // --------------------------------------------------------------------
100
101 /**
102 * Query result. Acts as a wrapper function for the following functions.
103 *
104 * @access public
105 * @param string can be "object" or "array"
106 * @return mixed either a result object or array
107 */
108 function row($n = 0, $type = 'object')
109 {
110 return ($type == 'object') ? $this->row_object($n) : $this->row_array($n);
111 }
112
113 // --------------------------------------------------------------------
114
115 /**
116 * Returns a single result row - object version
117 *
118 * @access public
119 * @return object
120 */
121 function row_object($n = 0)
122 {
adminaf644692006-10-05 04:22:41 +0000123 $result = $this->result_object();
124
125 if (count($result) == 0)
admin7b613c72006-09-24 18:05:17 +0000126 {
adminaf644692006-10-05 04:22:41 +0000127 return $result;
admin7b613c72006-09-24 18:05:17 +0000128 }
adminaf644692006-10-05 04:22:41 +0000129
admin7b613c72006-09-24 18:05:17 +0000130 if ($n != $this->current_row AND isset($result[$n]))
131 {
132 $this->current_row = $n;
133 }
adminaf644692006-10-05 04:22:41 +0000134
admin7b613c72006-09-24 18:05:17 +0000135 return $result[$this->current_row];
136 }
137
138 // --------------------------------------------------------------------
139
140 /**
141 * Returns a single result row - array version
142 *
143 * @access public
144 * @return array
145 */
146 function row_array($n = 0)
147 {
adminaf644692006-10-05 04:22:41 +0000148 $result = $this->result_array();
149
150 if (count($result) == 0)
admin7b613c72006-09-24 18:05:17 +0000151 {
adminaf644692006-10-05 04:22:41 +0000152 return $result;
admin7b613c72006-09-24 18:05:17 +0000153 }
154
155 if ($n != $this->current_row AND isset($result[$n]))
156 {
157 $this->current_row = $n;
158 }
159
160 return $result[$this->current_row];
161 }
162
163
164 // --------------------------------------------------------------------
165
166 /**
167 * Returns the "first" row
168 *
169 * @access public
170 * @return object
171 */
172 function first_row($type = 'object')
173 {
adminaf644692006-10-05 04:22:41 +0000174 $result = $this->result($type);
175
176 if (count($result) == 0)
admin7b613c72006-09-24 18:05:17 +0000177 {
adminaf644692006-10-05 04:22:41 +0000178 return $result;
admin7b613c72006-09-24 18:05:17 +0000179 }
180 return $result[0];
181 }
182
183 // --------------------------------------------------------------------
184
185 /**
186 * Returns the "last" row
187 *
188 * @access public
189 * @return object
190 */
191 function last_row($type = 'object')
192 {
adminaf644692006-10-05 04:22:41 +0000193 $result = $this->result($type);
194
195 if (count($result) == 0)
admin7b613c72006-09-24 18:05:17 +0000196 {
adminaf644692006-10-05 04:22:41 +0000197 return $result;
admin7b613c72006-09-24 18:05:17 +0000198 }
199 return $result[count($result) -1];
200 }
201
202 // --------------------------------------------------------------------
203
204 /**
205 * Returns the "next" row
206 *
207 * @access public
208 * @return object
209 */
210 function next_row($type = 'object')
211 {
adminaf644692006-10-05 04:22:41 +0000212 $result = $this->result($type);
213
214 if (count($result) == 0)
admin7b613c72006-09-24 18:05:17 +0000215 {
adminaf644692006-10-05 04:22:41 +0000216 return $result;
admin7b613c72006-09-24 18:05:17 +0000217 }
218
219 if (isset($result[$this->current_row + 1]))
220 {
221 ++$this->current_row;
222 }
223
224 return $result[$this->current_row];
225 }
226
227 // --------------------------------------------------------------------
228
229 /**
230 * Returns the "previous" row
231 *
232 * @access public
233 * @return object
234 */
235 function previous_row($type = 'object')
236 {
adminaf644692006-10-05 04:22:41 +0000237 $result = $this->result($type);
238
239 if (count($result) == 0)
admin7b613c72006-09-24 18:05:17 +0000240 {
adminaf644692006-10-05 04:22:41 +0000241 return $result;
admin7b613c72006-09-24 18:05:17 +0000242 }
243
244 if (isset($result[$this->current_row - 1]))
245 {
246 --$this->current_row;
247 }
248 return $result[$this->current_row];
249 }
250
admine1063182006-09-25 22:12:16 +0000251 // --------------------------------------------------------------------
252
253 /**
254 * Number of rows in the result set
255 *
admin7b9d4722006-10-05 04:46:47 +0000256 * Note: This function is normally overloaded by the identically named
257 * method in the platform-specific driver -- except when query caching
258 * is used. When caching is enabled we do not load the other driver,
259 * so this function is here primarily to prevent undefined function errors.
260 *
admine1063182006-09-25 22:12:16 +0000261 * @access public
262 * @return integer
263 */
264 function num_rows()
265 {
adminaf644692006-10-05 04:22:41 +0000266 return $this->num_rows;
admine1063182006-09-25 22:12:16 +0000267 }
268
269 // --------------------------------------------------------------------
270
271 /**
272 * Number of fields in the result set
273 *
admin7b9d4722006-10-05 04:46:47 +0000274 * Note: This function is normally overloaded by the identically named
275 * method in the platform-specific driver -- except when query caching
276 * is used. When caching is enabled we do not load the other driver,
277 * so this function is here primarily to prevent undefined function errors.
278 *
admine1063182006-09-25 22:12:16 +0000279 * @access public
280 * @return integer
281 */
282 function num_fields()
283 {
adminaf644692006-10-05 04:22:41 +0000284 return 0;
admine1063182006-09-25 22:12:16 +0000285 }
adminaf644692006-10-05 04:22:41 +0000286
admine1063182006-09-25 22:12:16 +0000287 // --------------------------------------------------------------------
288
289 /**
290 * Fetch Field Names
291 *
admin7b9d4722006-10-05 04:46:47 +0000292 * Note: This function is normally overloaded by the identically named
293 * method in the platform-specific driver -- except when query caching
294 * is used. When caching is enabled we do not load the other driver,
295 * so this function is here primarily to prevent undefined function errors.
admine1063182006-09-25 22:12:16 +0000296 *
297 * @access public
298 * @return array
299 */
300 function field_names()
adminaf644692006-10-05 04:22:41 +0000301 {
302 return array();
admine1063182006-09-25 22:12:16 +0000303 }
304
305 // --------------------------------------------------------------------
306
307 /**
308 * Field data
309 *
admin7b9d4722006-10-05 04:46:47 +0000310 * Note: This function is normally overloaded by the identically named
311 * method in the platform-specific driver -- except when query caching
312 * is used. When caching is enabled we do not load the other driver,
313 * so this function is here primarily to prevent undefined function errors.
admine1063182006-09-25 22:12:16 +0000314 *
315 * @access public
316 * @return array
317 */
318 function field_data()
319 {
adminaf644692006-10-05 04:22:41 +0000320 $F = new stdClass();
321 $F->name = NULL;
322 $F->type = NULL;
323 $F->default = NULL;
324 $F->max_length = NULL;
325 $F->primary_key = NULL;
326
327 return $retval[] = $F;
admine1063182006-09-25 22:12:16 +0000328 }
adminaf644692006-10-05 04:22:41 +0000329
admine1063182006-09-25 22:12:16 +0000330 // --------------------------------------------------------------------
331
332 /**
333 * Free the result
334 *
admin7b9d4722006-10-05 04:46:47 +0000335 * Note: This function is normally overloaded by the identically named
336 * method in the platform-specific driver -- except when query caching
337 * is used. When caching is enabled we do not load the other driver,
338 * so this function is here primarily to prevent undefined function errors.
339 *
admine1063182006-09-25 22:12:16 +0000340 * @return null
341 */
342 function free_result()
343 {
adminaf644692006-10-05 04:22:41 +0000344 return TRUE;
admine1063182006-09-25 22:12:16 +0000345 }
346
adminaf644692006-10-05 04:22:41 +0000347 // --------------------------------------------------------------------
348
349 /**
350 * Data Seek
351 *
admin7b9d4722006-10-05 04:46:47 +0000352 * Note: This function is normally overloaded by the identically named
353 * method in the platform-specific driver -- except when query caching
354 * is used. When caching is enabled we do not load the other driver,
355 * so this function is here primarily to prevent undefined function errors.
adminaf644692006-10-05 04:22:41 +0000356 *
357 * @access private
358 * @return array
359 */
admin7b9d4722006-10-05 04:46:47 +0000360 function _data_seek()
adminaf644692006-10-05 04:22:41 +0000361 {
362 return TRUE;
363 }
364
365 // --------------------------------------------------------------------
366
367 /**
368 * Result - associative array
369 *
admin7b9d4722006-10-05 04:46:47 +0000370 * Note: This function is normally overloaded by the identically named
371 * method in the platform-specific driver -- except when query caching
372 * is used. When caching is enabled we do not load the other driver,
373 * so this function is here primarily to prevent undefined function errors.
adminaf644692006-10-05 04:22:41 +0000374 *
375 * @access private
376 * @return array
377 */
378 function _fetch_assoc()
379 {
380 return array();
381 }
382
383 // --------------------------------------------------------------------
384
385 /**
386 * Result - object
387 *
admin7b9d4722006-10-05 04:46:47 +0000388 * Note: This function is normally overloaded by the identically named
389 * method in the platform-specific driver -- except when query caching
390 * is used. When caching is enabled we do not load the other driver,
391 * so this function is here primarily to prevent undefined function errors.
adminaf644692006-10-05 04:22:41 +0000392 *
393 * @access private
394 * @return object
395 */
396 function _fetch_object()
397 {
398 return array();
399 }
admine1063182006-09-25 22:12:16 +0000400
admin7b613c72006-09-24 18:05:17 +0000401}
admin7b9d4722006-10-05 04:46:47 +0000402// END DB_result class
admin7b613c72006-09-24 18:05:17 +0000403?>