DB_result.php
Go to the documentation of this file.00001 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 class CI_DB_result {
00030
00031 var $conn_id = NULL;
00032 var $result_id = NULL;
00033 var $result_array = array();
00034 var $result_object = array();
00035 var $current_row = 0;
00036 var $num_rows = 0;
00037 var $row_data = NULL;
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 function result($type = 'object')
00048 {
00049 return ($type == 'object') ? $this->result_object() : $this->result_array();
00050 }
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 function result_object()
00061 {
00062 if (count($this->result_object) > 0)
00063 {
00064 return $this->result_object;
00065 }
00066
00067
00068
00069
00070 if ($this->result_id === FALSE OR $this->num_rows() == 0)
00071 {
00072 return array();
00073 }
00074
00075 $this->_data_seek(0);
00076 while ($row = $this->_fetch_object())
00077 {
00078 $this->result_object[] = $row;
00079 }
00080
00081 return $this->result_object;
00082 }
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 function result_array()
00093 {
00094 if (count($this->result_array) > 0)
00095 {
00096 return $this->result_array;
00097 }
00098
00099
00100
00101
00102 if ($this->result_id === FALSE OR $this->num_rows() == 0)
00103 {
00104 return array();
00105 }
00106
00107 $this->_data_seek(0);
00108 while ($row = $this->_fetch_assoc())
00109 {
00110 $this->result_array[] = $row;
00111 }
00112
00113 return $this->result_array;
00114 }
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 function row($n = 0, $type = 'object')
00127 {
00128 if ( ! is_numeric($n))
00129 {
00130
00131 if ( ! is_array($this->row_data))
00132 {
00133 $this->row_data = $this->row_array(0);
00134 }
00135
00136
00137 if (array_key_exists($n, $this->row_data))
00138 {
00139 return $this->row_data[$n];
00140 }
00141
00142 $n = 0;
00143 }
00144
00145 return ($type == 'object') ? $this->row_object($n) : $this->row_array($n);
00146 }
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156 function set_row($key, $value = NULL)
00157 {
00158
00159 if ( ! is_array($this->row_data))
00160 {
00161 $this->row_data = $this->row_array(0);
00162 }
00163
00164 if (is_array($key))
00165 {
00166 foreach ($key as $k => $v)
00167 {
00168 $this->row_data[$k] = $v;
00169 }
00170
00171 return;
00172 }
00173
00174 if ($key != '' AND ! is_null($value))
00175 {
00176 $this->row_data[$key] = $value;
00177 }
00178 }
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188 function row_object($n = 0)
00189 {
00190 $result = $this->result_object();
00191
00192 if (count($result) == 0)
00193 {
00194 return $result;
00195 }
00196
00197 if ($n != $this->current_row AND isset($result[$n]))
00198 {
00199 $this->current_row = $n;
00200 }
00201
00202 return $result[$this->current_row];
00203 }
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213 function row_array($n = 0)
00214 {
00215 $result = $this->result_array();
00216
00217 if (count($result) == 0)
00218 {
00219 return $result;
00220 }
00221
00222 if ($n != $this->current_row AND isset($result[$n]))
00223 {
00224 $this->current_row = $n;
00225 }
00226
00227 return $result[$this->current_row];
00228 }
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239 function first_row($type = 'object')
00240 {
00241 $result = $this->result($type);
00242
00243 if (count($result) == 0)
00244 {
00245 return $result;
00246 }
00247 return $result[0];
00248 }
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258 function last_row($type = 'object')
00259 {
00260 $result = $this->result($type);
00261
00262 if (count($result) == 0)
00263 {
00264 return $result;
00265 }
00266 return $result[count($result) -1];
00267 }
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277 function next_row($type = 'object')
00278 {
00279 $result = $this->result($type);
00280
00281 if (count($result) == 0)
00282 {
00283 return $result;
00284 }
00285
00286 if (isset($result[$this->current_row + 1]))
00287 {
00288 ++$this->current_row;
00289 }
00290
00291 return $result[$this->current_row];
00292 }
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302 function previous_row($type = 'object')
00303 {
00304 $result = $this->result($type);
00305
00306 if (count($result) == 0)
00307 {
00308 return $result;
00309 }
00310
00311 if (isset($result[$this->current_row - 1]))
00312 {
00313 --$this->current_row;
00314 }
00315 return $result[$this->current_row];
00316 }
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329 function num_rows() { return $this->num_rows; }
00330 function num_fields() { return 0; }
00331 function list_fields() { return array(); }
00332 function field_data() { return array(); }
00333 function free_result() { return TRUE; }
00334 function _data_seek() { return TRUE; }
00335 function _fetch_assoc() { return array(); }
00336 function _fetch_object() { return array(); }
00337
00338 }
00339
00340
00341
00342