Andrey Andreev | 24276a3 | 2012-01-08 02:44:38 +0200 | [diff] [blame^] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Greg Aker | 741de1c | 2010-11-10 14:52:57 -0600 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.1.6 or newer |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 7 | * NOTICE OF LICENSE |
Andrey Andreev | 24276a3 | 2012-01-08 02:44:38 +0200 | [diff] [blame^] | 8 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 9 | * Licensed under the Open Software License version 3.0 |
Andrey Andreev | 24276a3 | 2012-01-08 02:44:38 +0200 | [diff] [blame^] | 10 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 11 | * This source file is subject to the Open Software License (OSL 3.0) that is |
| 12 | * bundled with this package in the files license.txt / license.rst. It is |
| 13 | * also available through the world wide web at this URL: |
| 14 | * http://opensource.org/licenses/OSL-3.0 |
| 15 | * If you did not receive a copy of the license and are unable to obtain it |
| 16 | * through the world wide web, please send an email to |
| 17 | * licensing@ellislab.com so we can send you a copy immediately. |
| 18 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 19 | * @package CodeIgniter |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 20 | * @author EllisLab Dev Team |
Greg Aker | 0defe5d | 2012-01-01 18:46:41 -0600 | [diff] [blame] | 21 | * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 23 | * @link http://codeigniter.com |
| 24 | * @since Version 1.0 |
| 25 | * @filesource |
| 26 | */ |
| 27 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 28 | /** |
| 29 | * Database Result Class |
| 30 | * |
| 31 | * This is the platform-independent result class. |
| 32 | * This class will not be called directly. Rather, the adapter |
| 33 | * class for the specific database will extend and instantiate it. |
| 34 | * |
| 35 | * @category Database |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 36 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 37 | * @link http://codeigniter.com/user_guide/database/ |
| 38 | */ |
| 39 | class CI_DB_result { |
| 40 | |
Andrey Andreev | 24276a3 | 2012-01-08 02:44:38 +0200 | [diff] [blame^] | 41 | public $conn_id = NULL; |
| 42 | public $result_id = NULL; |
| 43 | public $result_array = array(); |
| 44 | public $result_object = array(); |
| 45 | public $custom_result_object = array(); |
| 46 | public $current_row = 0; |
| 47 | public $num_rows = 0; |
| 48 | public $row_data = NULL; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 49 | |
| 50 | /** |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 51 | * Query result. Acts as a wrapper function for the following functions. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 52 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 53 | * @param string can be "object" or "array" |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 54 | * @return mixed either a result object or array |
| 55 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 56 | public function result($type = 'object') |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 57 | { |
Andrey Andreev | 24276a3 | 2012-01-08 02:44:38 +0200 | [diff] [blame^] | 58 | if ($type === 'array') return $this->result_array(); |
| 59 | elseif ($type === 'object') return $this->result_object(); |
Greg Aker | e70e92b | 2011-04-25 10:50:53 -0500 | [diff] [blame] | 60 | else return $this->custom_result_object($type); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | // -------------------------------------------------------------------- |
| 64 | |
Greg Aker | e70e92b | 2011-04-25 10:50:53 -0500 | [diff] [blame] | 65 | /** |
| 66 | * Custom query result. |
| 67 | * |
Andrey Andreev | 24276a3 | 2012-01-08 02:44:38 +0200 | [diff] [blame^] | 68 | * @param string A string that represents the type of object you want back |
| 69 | * @return array of objects |
Greg Aker | e70e92b | 2011-04-25 10:50:53 -0500 | [diff] [blame] | 70 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 71 | public function custom_result_object($class_name) |
Greg Aker | e70e92b | 2011-04-25 10:50:53 -0500 | [diff] [blame] | 72 | { |
| 73 | if (array_key_exists($class_name, $this->custom_result_object)) |
| 74 | { |
| 75 | return $this->custom_result_object[$class_name]; |
| 76 | } |
John Crepezzi | 7b47430 | 2011-01-15 18:17:01 -0500 | [diff] [blame] | 77 | |
Greg Aker | e70e92b | 2011-04-25 10:50:53 -0500 | [diff] [blame] | 78 | if ($this->result_id === FALSE OR $this->num_rows() == 0) |
| 79 | { |
| 80 | return array(); |
| 81 | } |
Razican | 114ab09 | 2011-04-25 17:26:45 +0200 | [diff] [blame] | 82 | |
Greg Aker | e70e92b | 2011-04-25 10:50:53 -0500 | [diff] [blame] | 83 | // add the data to the object |
| 84 | $this->_data_seek(0); |
| 85 | $result_object = array(); |
| 86 | |
John Crepezzi | 7b47430 | 2011-01-15 18:17:01 -0500 | [diff] [blame] | 87 | while ($row = $this->_fetch_object()) |
Greg Aker | e70e92b | 2011-04-25 10:50:53 -0500 | [diff] [blame] | 88 | { |
| 89 | $object = new $class_name(); |
Greg Aker | e70e92b | 2011-04-25 10:50:53 -0500 | [diff] [blame] | 90 | foreach ($row as $key => $value) |
| 91 | { |
| 92 | $object->$key = $value; |
| 93 | } |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 94 | |
John Crepezzi | 7b47430 | 2011-01-15 18:17:01 -0500 | [diff] [blame] | 95 | $result_object[] = $object; |
| 96 | } |
| 97 | |
Greg Aker | e70e92b | 2011-04-25 10:50:53 -0500 | [diff] [blame] | 98 | // return the array |
| 99 | return $this->custom_result_object[$class_name] = $result_object; |
| 100 | } |
| 101 | |
| 102 | // -------------------------------------------------------------------- |
John Crepezzi | 7b47430 | 2011-01-15 18:17:01 -0500 | [diff] [blame] | 103 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 104 | /** |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 105 | * Query result. "object" version. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 106 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 107 | * @return object |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 108 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 109 | public function result_object() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 110 | { |
| 111 | if (count($this->result_object) > 0) |
| 112 | { |
| 113 | return $this->result_object; |
| 114 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 115 | |
| 116 | // In the event that query caching is on the result_id variable |
| 117 | // will return FALSE since there isn't a valid SQL resource so |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 118 | // we'll simply return an empty array. |
| 119 | if ($this->result_id === FALSE OR $this->num_rows() == 0) |
| 120 | { |
| 121 | return array(); |
| 122 | } |
| 123 | |
| 124 | $this->_data_seek(0); |
| 125 | while ($row = $this->_fetch_object()) |
| 126 | { |
| 127 | $this->result_object[] = $row; |
| 128 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 129 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 130 | return $this->result_object; |
| 131 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 132 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 133 | // -------------------------------------------------------------------- |
| 134 | |
| 135 | /** |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 136 | * Query result. "array" version. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 137 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 138 | * @return array |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 139 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 140 | public function result_array() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 141 | { |
| 142 | if (count($this->result_array) > 0) |
| 143 | { |
| 144 | return $this->result_array; |
| 145 | } |
| 146 | |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 147 | // In the event that query caching is on the result_id variable |
| 148 | // will return FALSE since there isn't a valid SQL resource so |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 149 | // we'll simply return an empty array. |
| 150 | if ($this->result_id === FALSE OR $this->num_rows() == 0) |
| 151 | { |
| 152 | return array(); |
| 153 | } |
| 154 | |
| 155 | $this->_data_seek(0); |
| 156 | while ($row = $this->_fetch_assoc()) |
| 157 | { |
| 158 | $this->result_array[] = $row; |
| 159 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 160 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 161 | return $this->result_array; |
| 162 | } |
| 163 | |
| 164 | // -------------------------------------------------------------------- |
| 165 | |
| 166 | /** |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 167 | * Query result. Acts as a wrapper function for the following functions. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 168 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 169 | * @param string |
| 170 | * @param string can be "object" or "array" |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 171 | * @return mixed either a result object or array |
| 172 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 173 | public function row($n = 0, $type = 'object') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 174 | { |
| 175 | if ( ! is_numeric($n)) |
| 176 | { |
| 177 | // We cache the row data for subsequent uses |
| 178 | if ( ! is_array($this->row_data)) |
| 179 | { |
| 180 | $this->row_data = $this->row_array(0); |
| 181 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 182 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 183 | // array_key_exists() instead of isset() to allow for MySQL NULL values |
| 184 | if (array_key_exists($n, $this->row_data)) |
| 185 | { |
| 186 | return $this->row_data[$n]; |
| 187 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 188 | // reset the $n variable if the result was not achieved |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 189 | $n = 0; |
| 190 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 191 | |
Andrey Andreev | 24276a3 | 2012-01-08 02:44:38 +0200 | [diff] [blame^] | 192 | if ($type === 'object') return $this->row_object($n); |
| 193 | elseif ($type === 'array') return $this->row_array($n); |
Greg Aker | e70e92b | 2011-04-25 10:50:53 -0500 | [diff] [blame] | 194 | else return $this->custom_row_object($n, $type); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | // -------------------------------------------------------------------- |
| 198 | |
| 199 | /** |
| 200 | * Assigns an item into a particular column slot |
| 201 | * |
Andrey Andreev | 24276a3 | 2012-01-08 02:44:38 +0200 | [diff] [blame^] | 202 | * @return void |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 203 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 204 | public function set_row($key, $value = NULL) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 205 | { |
| 206 | // We cache the row data for subsequent uses |
| 207 | if ( ! is_array($this->row_data)) |
| 208 | { |
| 209 | $this->row_data = $this->row_array(0); |
| 210 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 211 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 212 | if (is_array($key)) |
| 213 | { |
| 214 | foreach ($key as $k => $v) |
| 215 | { |
| 216 | $this->row_data[$k] = $v; |
| 217 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 218 | return; |
| 219 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 220 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 221 | if ($key != '' AND ! is_null($value)) |
| 222 | { |
| 223 | $this->row_data[$key] = $value; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | // -------------------------------------------------------------------- |
| 228 | |
Greg Aker | e70e92b | 2011-04-25 10:50:53 -0500 | [diff] [blame] | 229 | /** |
John Crepezzi | 7b47430 | 2011-01-15 18:17:01 -0500 | [diff] [blame] | 230 | * Returns a single result row - custom object version |
| 231 | * |
John Crepezzi | 7b47430 | 2011-01-15 18:17:01 -0500 | [diff] [blame] | 232 | * @return object |
| 233 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 234 | public function custom_row_object($n, $type) |
John Crepezzi | 7b47430 | 2011-01-15 18:17:01 -0500 | [diff] [blame] | 235 | { |
| 236 | $result = $this->custom_result_object($type); |
Andrey Andreev | 24276a3 | 2012-01-08 02:44:38 +0200 | [diff] [blame^] | 237 | if (count($result) === 0) |
John Crepezzi | 7b47430 | 2011-01-15 18:17:01 -0500 | [diff] [blame] | 238 | { |
| 239 | return $result; |
| 240 | } |
| 241 | |
| 242 | if ($n != $this->current_row AND isset($result[$n])) |
| 243 | { |
| 244 | $this->current_row = $n; |
| 245 | } |
| 246 | |
| 247 | return $result[$this->current_row]; |
| 248 | } |
| 249 | |
Greg Aker | e70e92b | 2011-04-25 10:50:53 -0500 | [diff] [blame] | 250 | /** |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 251 | * Returns a single result row - object version |
| 252 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 253 | * @return object |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 254 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 255 | public function row_object($n = 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 256 | { |
| 257 | $result = $this->result_object(); |
Andrey Andreev | 24276a3 | 2012-01-08 02:44:38 +0200 | [diff] [blame^] | 258 | if (count($result) === 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 259 | { |
| 260 | return $result; |
| 261 | } |
| 262 | |
| 263 | if ($n != $this->current_row AND isset($result[$n])) |
| 264 | { |
| 265 | $this->current_row = $n; |
| 266 | } |
| 267 | |
| 268 | return $result[$this->current_row]; |
| 269 | } |
| 270 | |
| 271 | // -------------------------------------------------------------------- |
| 272 | |
| 273 | /** |
| 274 | * Returns a single result row - array version |
| 275 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 276 | * @return array |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 277 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 278 | public function row_array($n = 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 279 | { |
| 280 | $result = $this->result_array(); |
Andrey Andreev | 24276a3 | 2012-01-08 02:44:38 +0200 | [diff] [blame^] | 281 | if (count($result) === 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 282 | { |
| 283 | return $result; |
| 284 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 285 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 286 | if ($n != $this->current_row AND isset($result[$n])) |
| 287 | { |
| 288 | $this->current_row = $n; |
| 289 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 290 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 291 | return $result[$this->current_row]; |
| 292 | } |
| 293 | |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 294 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 295 | // -------------------------------------------------------------------- |
| 296 | |
| 297 | /** |
| 298 | * Returns the "first" row |
| 299 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 300 | * @return object |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 301 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 302 | public function first_row($type = 'object') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 303 | { |
| 304 | $result = $this->result($type); |
Andrey Andreev | 24276a3 | 2012-01-08 02:44:38 +0200 | [diff] [blame^] | 305 | return (count($result) === 0) ? $result : $result[0]; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 306 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 307 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 308 | // -------------------------------------------------------------------- |
| 309 | |
| 310 | /** |
| 311 | * Returns the "last" row |
| 312 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 313 | * @return object |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 314 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 315 | public function last_row($type = 'object') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 316 | { |
| 317 | $result = $this->result($type); |
Andrey Andreev | 24276a3 | 2012-01-08 02:44:38 +0200 | [diff] [blame^] | 318 | return (count($result) === 0) ? $result : $result[count($result) - 1]; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 319 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 320 | |
| 321 | // -------------------------------------------------------------------- |
| 322 | |
| 323 | /** |
| 324 | * Returns the "next" row |
| 325 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 326 | * @return object |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 327 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 328 | public function next_row($type = 'object') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 329 | { |
| 330 | $result = $this->result($type); |
Andrey Andreev | 24276a3 | 2012-01-08 02:44:38 +0200 | [diff] [blame^] | 331 | if (count($result) === 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 332 | { |
| 333 | return $result; |
| 334 | } |
| 335 | |
| 336 | if (isset($result[$this->current_row + 1])) |
| 337 | { |
| 338 | ++$this->current_row; |
| 339 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 340 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 341 | return $result[$this->current_row]; |
| 342 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 343 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 344 | // -------------------------------------------------------------------- |
| 345 | |
| 346 | /** |
| 347 | * Returns the "previous" row |
| 348 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 349 | * @return object |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 350 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 351 | public function previous_row($type = 'object') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 352 | { |
| 353 | $result = $this->result($type); |
Andrey Andreev | 24276a3 | 2012-01-08 02:44:38 +0200 | [diff] [blame^] | 354 | if (count($result) === 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 355 | { |
| 356 | return $result; |
| 357 | } |
| 358 | |
| 359 | if (isset($result[$this->current_row - 1])) |
| 360 | { |
| 361 | --$this->current_row; |
| 362 | } |
| 363 | return $result[$this->current_row]; |
| 364 | } |
| 365 | |
| 366 | // -------------------------------------------------------------------- |
| 367 | |
| 368 | /** |
| 369 | * The following functions are normally overloaded by the identically named |
| 370 | * methods in the platform-specific driver -- except when query caching |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 371 | * is used. When caching is enabled we do not load the other driver. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 372 | * These functions are primarily here to prevent undefined function errors |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 373 | * when a cached result object is in use. They are not otherwise fully |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 374 | * operational due to the unavailability of the database resource IDs with |
| 375 | * cached results. |
| 376 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 377 | public function num_rows() { return $this->num_rows; } |
| 378 | public function num_fields() { return 0; } |
| 379 | public function list_fields() { return array(); } |
| 380 | public function field_data() { return array(); } |
| 381 | public function free_result() { return TRUE; } |
| 382 | protected function _data_seek() { return TRUE; } |
| 383 | protected function _fetch_assoc() { return array(); } |
| 384 | protected function _fetch_object() { return array(); } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 385 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 386 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 387 | |
| 388 | /* End of file DB_result.php */ |
John Crepezzi | 7b47430 | 2011-01-15 18:17:01 -0500 | [diff] [blame] | 389 | /* Location: ./system/database/DB_result.php */ |