Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 1 | ######################## |
| 2 | Generating Query Results |
| 3 | ######################## |
| 4 | |
| 5 | There are several ways to generate query results: |
| 6 | |
James L Parry | 1516219 | 2014-12-05 23:40:47 -0800 | [diff] [blame] | 7 | .. contents:: |
| 8 | :local: |
| 9 | :depth: 2 |
| 10 | |
James L Parry | 014bc89 | 2014-11-24 17:14:19 -0800 | [diff] [blame] | 11 | ************* |
| 12 | Result Arrays |
| 13 | ************* |
| 14 | |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 15 | **result()** |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 16 | |
James L Parry | e4a9f64 | 2014-11-24 16:20:53 -0800 | [diff] [blame] | 17 | This method returns the query result as an array of **objects**, or |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 18 | **an empty array** on failure. Typically you'll use this in a foreach |
| 19 | loop, like this:: |
| 20 | |
Joseph Wensley | f24f404 | 2011-10-06 22:53:29 -0400 | [diff] [blame] | 21 | $query = $this->db->query("YOUR QUERY"); |
| 22 | |
| 23 | foreach ($query->result() as $row) |
| 24 | { |
| 25 | echo $row->title; |
| 26 | echo $row->name; |
| 27 | echo $row->body; |
| 28 | } |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 29 | |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 30 | The above method is an alias of ``result_object()``. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 31 | |
| 32 | If you run queries that might **not** produce a result, you are |
| 33 | encouraged to test the result first:: |
| 34 | |
Joseph Wensley | f24f404 | 2011-10-06 22:53:29 -0400 | [diff] [blame] | 35 | $query = $this->db->query("YOUR QUERY"); |
| 36 | |
| 37 | if ($query->num_rows() > 0) |
| 38 | { |
| 39 | foreach ($query->result() as $row) |
| 40 | { |
| 41 | echo $row->title; |
| 42 | echo $row->name; |
| 43 | echo $row->body; |
| 44 | } |
| 45 | } |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 46 | |
| 47 | You can also pass a string to result() which represents a class to |
| 48 | instantiate for each result object (note: this class must be loaded) |
| 49 | |
| 50 | :: |
| 51 | |
| 52 | $query = $this->db->query("SELECT * FROM users;"); |
| 53 | |
| 54 | foreach ($query->result('User') as $user) |
| 55 | { |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 56 | echo $user->name; // access attributes |
| 57 | echo $user->reverse_name(); // or methods defined on the 'User' class |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 58 | } |
| 59 | |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 60 | **result_array()** |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 61 | |
James L Parry | e4a9f64 | 2014-11-24 16:20:53 -0800 | [diff] [blame] | 62 | This method returns the query result as a pure array, or an empty |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 63 | array when no result is produced. Typically you'll use this in a foreach |
| 64 | loop, like this:: |
| 65 | |
Joseph Wensley | f24f404 | 2011-10-06 22:53:29 -0400 | [diff] [blame] | 66 | $query = $this->db->query("YOUR QUERY"); |
| 67 | |
| 68 | foreach ($query->result_array() as $row) |
| 69 | { |
| 70 | echo $row['title']; |
| 71 | echo $row['name']; |
| 72 | echo $row['body']; |
| 73 | } |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 74 | |
James L Parry | 014bc89 | 2014-11-24 17:14:19 -0800 | [diff] [blame] | 75 | *********** |
| 76 | Result Rows |
| 77 | *********** |
| 78 | |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 79 | **row()** |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 80 | |
James L Parry | e4a9f64 | 2014-11-24 16:20:53 -0800 | [diff] [blame] | 81 | This method returns a single result row. If your query has more than |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 82 | one row, it returns only the first row. The result is returned as an |
| 83 | **object**. Here's a usage example:: |
| 84 | |
Joseph Wensley | f24f404 | 2011-10-06 22:53:29 -0400 | [diff] [blame] | 85 | $query = $this->db->query("YOUR QUERY"); |
| 86 | |
| 87 | if ($query->num_rows() > 0) |
| 88 | { |
| 89 | $row = $query->row(); |
| 90 | |
| 91 | echo $row->title; |
| 92 | echo $row->name; |
| 93 | echo $row->body; |
| 94 | } |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 95 | |
| 96 | If you want a specific row returned you can submit the row number as a |
| 97 | digit in the first parameter:: |
| 98 | |
| 99 | $row = $query->row(5); |
| 100 | |
| 101 | You can also add a second String parameter, which is the name of a class |
| 102 | to instantiate the row with:: |
| 103 | |
Joseph Wensley | f24f404 | 2011-10-06 22:53:29 -0400 | [diff] [blame] | 104 | $query = $this->db->query("SELECT * FROM users LIMIT 1;"); |
| 105 | $query->row(0, 'User'); |
| 106 | |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 107 | echo $row->name; // access attributes |
Joseph Wensley | f24f404 | 2011-10-06 22:53:29 -0400 | [diff] [blame] | 108 | echo $row->reverse_name(); // or methods defined on the 'User' class |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 109 | |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 110 | **row_array()** |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 111 | |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 112 | Identical to the above ``row()`` method, except it returns an array. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 113 | Example:: |
| 114 | |
Joseph Wensley | f24f404 | 2011-10-06 22:53:29 -0400 | [diff] [blame] | 115 | $query = $this->db->query("YOUR QUERY"); |
| 116 | |
| 117 | if ($query->num_rows() > 0) |
| 118 | { |
| 119 | $row = $query->row_array(); |
| 120 | |
| 121 | echo $row['title']; |
| 122 | echo $row['name']; |
| 123 | echo $row['body']; |
| 124 | } |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 125 | |
| 126 | If you want a specific row returned you can submit the row number as a |
| 127 | digit in the first parameter:: |
| 128 | |
| 129 | $row = $query->row_array(5); |
| 130 | |
| 131 | In addition, you can walk forward/backwards/first/last through your |
| 132 | results using these variations: |
| 133 | |
Joseph Wensley | f24f404 | 2011-10-06 22:53:29 -0400 | [diff] [blame] | 134 | | **$row = $query->first_row()** |
| 135 | | **$row = $query->last_row()** |
| 136 | | **$row = $query->next_row()** |
| 137 | | **$row = $query->previous_row()** |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 138 | |
| 139 | By default they return an object unless you put the word "array" in the |
| 140 | parameter: |
| 141 | |
Joseph Wensley | f24f404 | 2011-10-06 22:53:29 -0400 | [diff] [blame] | 142 | | **$row = $query->first_row('array')** |
| 143 | | **$row = $query->last_row('array')** |
| 144 | | **$row = $query->next_row('array')** |
| 145 | | **$row = $query->previous_row('array')** |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 146 | |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 147 | .. note:: All the methods above will load the whole result into memory |
| 148 | (prefetching). Use ``unbuffered_row()`` for processing large |
| 149 | result sets. |
Juan Ignacio Borda | d981e29 | 2012-05-18 18:29:24 -0300 | [diff] [blame] | 150 | |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 151 | **unbuffered_row()** |
Juan Ignacio Borda | d981e29 | 2012-05-18 18:29:24 -0300 | [diff] [blame] | 152 | |
Andrey Andreev | 69edc43 | 2012-12-04 13:32:16 +0200 | [diff] [blame] | 153 | This method returns a single result row without prefetching the whole |
| 154 | result in memory as ``row()`` does. If your query has more than one row, |
| 155 | it returns the current row and moves the internal data pointer ahead. |
Juan Ignacio Borda | d981e29 | 2012-05-18 18:29:24 -0300 | [diff] [blame] | 156 | |
Derek Jones | ce79be0 | 2012-06-25 23:23:46 -0700 | [diff] [blame] | 157 | :: |
Juan Ignacio Borda | d981e29 | 2012-05-18 18:29:24 -0300 | [diff] [blame] | 158 | |
| 159 | $query = $this->db->query("YOUR QUERY"); |
| 160 | |
Juan Ignacio Borda | da7c9e0 | 2012-05-19 09:42:40 -0300 | [diff] [blame] | 161 | while ($row = $query->unbuffered_row()) |
Juan Ignacio Borda | d981e29 | 2012-05-18 18:29:24 -0300 | [diff] [blame] | 162 | { |
| 163 | echo $row->title; |
| 164 | echo $row->name; |
| 165 | echo $row->body; |
| 166 | } |
| 167 | |
Andrey Andreev | 69edc43 | 2012-12-04 13:32:16 +0200 | [diff] [blame] | 168 | You can optionally pass 'object' (default) or 'array' in order to specify |
| 169 | the returned value's type:: |
| 170 | |
| 171 | $query->unbuffered_row(); // object |
| 172 | $query->unbuffered_row('object'); // object |
| 173 | $query->unbuffered_row('array'); // associative array |
| 174 | |
James L Parry | e4a9f64 | 2014-11-24 16:20:53 -0800 | [diff] [blame] | 175 | ********************* |
| 176 | Result Helper Methods |
| 177 | ********************* |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 178 | |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 179 | **num_rows()** |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 180 | |
| 181 | The number of rows returned by the query. Note: In this example, $query |
| 182 | is the variable that the query result object is assigned to:: |
| 183 | |
Joseph Wensley | f24f404 | 2011-10-06 22:53:29 -0400 | [diff] [blame] | 184 | $query = $this->db->query('SELECT * FROM my_table'); |
| 185 | |
| 186 | echo $query->num_rows(); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 187 | |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 188 | .. note:: Not all database drivers have a native way of getting the total |
Andrey Andreev | fdb7541 | 2012-03-05 16:32:17 +0200 | [diff] [blame] | 189 | number of rows for a result set. When this is the case, all of |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 190 | the data is prefetched and ``count()`` is manually called on the |
| 191 | resulting array in order to achieve the same result. |
Andrey Andreev | fdb7541 | 2012-03-05 16:32:17 +0200 | [diff] [blame] | 192 | |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 193 | **num_fields()** |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 194 | |
| 195 | The number of FIELDS (columns) returned by the query. Make sure to call |
James L Parry | e4a9f64 | 2014-11-24 16:20:53 -0800 | [diff] [blame] | 196 | the method using your query result object:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 197 | |
Joseph Wensley | f24f404 | 2011-10-06 22:53:29 -0400 | [diff] [blame] | 198 | $query = $this->db->query('SELECT * FROM my_table'); |
| 199 | |
| 200 | echo $query->num_fields(); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 201 | |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 202 | **free_result()** |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 203 | |
| 204 | It frees the memory associated with the result and deletes the result |
| 205 | resource ID. Normally PHP frees its memory automatically at the end of |
| 206 | script execution. However, if you are running a lot of queries in a |
| 207 | particular script you might want to free the result after each query |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 208 | result has been generated in order to cut down on memory consumption. |
| 209 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 210 | Example:: |
| 211 | |
Joseph Wensley | f24f404 | 2011-10-06 22:53:29 -0400 | [diff] [blame] | 212 | $query = $this->db->query('SELECT title FROM my_table'); |
| 213 | |
| 214 | foreach ($query->result() as $row) |
| 215 | { |
| 216 | echo $row->title; |
| 217 | } |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 218 | |
Joseph Wensley | f24f404 | 2011-10-06 22:53:29 -0400 | [diff] [blame] | 219 | $query->free_result(); // The $query result object will no longer be available |
| 220 | |
| 221 | $query2 = $this->db->query('SELECT name FROM some_table'); |
| 222 | |
| 223 | $row = $query2->row(); |
| 224 | echo $row->name; |
Andrey Andreev | fdb7541 | 2012-03-05 16:32:17 +0200 | [diff] [blame] | 225 | $query2->free_result(); // The $query2 result object will no longer be available |
Andrey Andreev | 69edc43 | 2012-12-04 13:32:16 +0200 | [diff] [blame] | 226 | |
James L Parry | e4a9f64 | 2014-11-24 16:20:53 -0800 | [diff] [blame] | 227 | **data_seek()** |
Andrey Andreev | 69edc43 | 2012-12-04 13:32:16 +0200 | [diff] [blame] | 228 | |
| 229 | This method sets the internal pointer for the next result row to be |
| 230 | fetched. It is only useful in combination with ``unbuffered_row()``. |
| 231 | |
| 232 | It accepts a positive integer value, which defaults to 0 and returns |
| 233 | TRUE on success or FALSE on failure. |
| 234 | |
| 235 | :: |
| 236 | |
| 237 | $query = $this->db->query('SELECT `field_name` FROM `table_name`'); |
| 238 | $query->data_seek(5); // Skip the first 5 rows |
| 239 | $row = $query->unbuffered_row(); |
| 240 | |
| 241 | .. note:: Not all database drivers support this feature and will return FALSE. |
James L Parry | 1516219 | 2014-12-05 23:40:47 -0800 | [diff] [blame] | 242 | Most notably - you won't be able to use it with PDO. |
| 243 | |
| 244 | *************** |
| 245 | Class Reference |
| 246 | *************** |
| 247 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 248 | .. php:class:: CI_DB_result |
James L Parry | 1516219 | 2014-12-05 23:40:47 -0800 | [diff] [blame] | 249 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 250 | .. php:method:: result([$type = 'object']) |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 251 | |
| 252 | :param string $type: Type of requested results - array, object, or class name |
| 253 | :returns: Array containing the fetched rows |
| 254 | :rtype: array |
| 255 | |
| 256 | A wrapper for the ``result_array()``, ``result_object()`` |
| 257 | and ``custom_result_object()`` methods. |
| 258 | |
| 259 | Usage: see `Result Arrays`_. |
| 260 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 261 | .. php:method:: result_array() |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 262 | |
| 263 | :returns: Array containing the fetched rows |
| 264 | :rtype: array |
| 265 | |
| 266 | Returns the query results as an array of rows, where each |
| 267 | row is itself an associative array. |
| 268 | |
| 269 | Usage: see `Result Arrays`_. |
| 270 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 271 | .. php:method:: result_object() |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 272 | |
| 273 | :returns: Array containing the fetched rows |
| 274 | :rtype: array |
| 275 | |
| 276 | Returns the query results as an array of rows, where each |
| 277 | row is an object of type ``stdClass``. |
| 278 | |
| 279 | Usage: see `Result Arrays`_. |
| 280 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 281 | .. php:method:: custom_result_object($class_name) |
James L Parry | 1516219 | 2014-12-05 23:40:47 -0800 | [diff] [blame] | 282 | |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 283 | :param string $class_name: Class name for the resulting rows |
| 284 | :returns: Array containing the fetched rows |
| 285 | :rtype: array |
James L Parry | 1516219 | 2014-12-05 23:40:47 -0800 | [diff] [blame] | 286 | |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 287 | Returns the query results as an array of rows, where each |
| 288 | row is an instance of the specified class. |
| 289 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 290 | .. php:method:: row([$n = 0[, $type = 'object']]) |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 291 | |
| 292 | :param int $n: Index of the query results row to be returned |
| 293 | :param string $type: Type of the requested result - array, object, or class name |
| 294 | :returns: The requested row or NULL if it doesn't exist |
| 295 | :rtype: mixed |
| 296 | |
| 297 | A wrapper for the ``row_array()``, ``row_object() and |
| 298 | ``custom_row_object()`` methods. |
| 299 | |
| 300 | Usage: see `Result Rows`_. |
| 301 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 302 | .. php:method:: unbuffered_row([$type = 'object']) |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 303 | |
| 304 | :param string $type: Type of the requested result - array, object, or class name |
| 305 | :returns: Next row from the result set or NULL if it doesn't exist |
| 306 | :rtype: mixed |
| 307 | |
| 308 | Fetches the next result row and returns it in the |
| 309 | requested form. |
| 310 | |
| 311 | Usage: see `Result Rows`_. |
| 312 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 313 | .. php:method:: row_array([$n = 0]) |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 314 | |
| 315 | :param int $n: Index of the query results row to be returned |
| 316 | :returns: The requested row or NULL if it doesn't exist |
| 317 | :rtype: array |
| 318 | |
| 319 | Returns the requested result row as an associative array. |
| 320 | |
| 321 | Usage: see `Result Rows`_. |
| 322 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 323 | .. php:method:: row_object([$n = 0]) |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 324 | |
| 325 | :param int $n: Index of the query results row to be returned |
| 326 | :returns: The requested row or NULL if it doesn't exist |
| 327 | :rtype: stdClass |
| 328 | |
| 329 | Returns the requested result row as an object of type |
| 330 | ``stdClass``. |
| 331 | |
| 332 | Usage: see `Result Rows`_. |
James L Parry | 1516219 | 2014-12-05 23:40:47 -0800 | [diff] [blame] | 333 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 334 | .. php:method:: custom_row_object($n, $type) |
James L Parry | 1516219 | 2014-12-05 23:40:47 -0800 | [diff] [blame] | 335 | |
| 336 | :param int $n: Index of the results row to return |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 337 | :param string $class_name: Class name for the resulting row |
| 338 | :returns: The requested row or NULL if it doesn't exist |
James L Parry | 1516219 | 2014-12-05 23:40:47 -0800 | [diff] [blame] | 339 | :rtype: $type |
| 340 | |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 341 | Returns the requested result row as an instance of the |
| 342 | requested class. |
James L Parry | 1516219 | 2014-12-05 23:40:47 -0800 | [diff] [blame] | 343 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 344 | .. php:method:: data_seek([$n = 0]) |
James L Parry | 1516219 | 2014-12-05 23:40:47 -0800 | [diff] [blame] | 345 | |
| 346 | :param int $n: Index of the results row to be returned next |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 347 | :returns: TRUE on success, FALSE on failure |
James L Parry | 1516219 | 2014-12-05 23:40:47 -0800 | [diff] [blame] | 348 | :rtype: bool |
| 349 | |
| 350 | Moves the internal results row pointer to the desired offset. |
James L Parry | 1516219 | 2014-12-05 23:40:47 -0800 | [diff] [blame] | 351 | |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 352 | Usage: see `Result Helper Methods`_. |
James L Parry | 1516219 | 2014-12-05 23:40:47 -0800 | [diff] [blame] | 353 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 354 | .. php:method:: set_row($key[, $value = NULL]) |
James L Parry | 1516219 | 2014-12-05 23:40:47 -0800 | [diff] [blame] | 355 | |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 356 | :param mixed $key: Column name or array of key/value pairs |
| 357 | :param mixed $value: Value to assign to the column, $key is a single field name |
| 358 | :rtype: void |
| 359 | |
| 360 | Assigns a value to a particular column. |
| 361 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 362 | .. php:method:: next_row([$type = 'object']) |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 363 | |
| 364 | :param string $type: Type of the requested result - array, object, or class name |
| 365 | :returns: Next row of result set, or NULL if it doesn't exist |
| 366 | :rtype: mixed |
| 367 | |
| 368 | Returns the next row from the result set. |
| 369 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 370 | .. php:method:: previous_row([$type = 'object']) |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 371 | |
| 372 | :param string $type: Type of the requested result - array, object, or class name |
| 373 | :returns: Previous row of result set, or NULL if it doesn't exist |
| 374 | :rtype: mixed |
| 375 | |
| 376 | Returns the previous row from the result set. |
James L Parry | 1516219 | 2014-12-05 23:40:47 -0800 | [diff] [blame] | 377 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 378 | .. php:method:: first_row([$type = 'object']) |
James L Parry | 1516219 | 2014-12-05 23:40:47 -0800 | [diff] [blame] | 379 | |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 380 | :param string $type: Type of the requested result - array, object, or class name |
| 381 | :returns: First row of result set, or NULL if it doesn't exist |
James L Parry | 1516219 | 2014-12-05 23:40:47 -0800 | [diff] [blame] | 382 | :rtype: mixed |
| 383 | |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 384 | Returns the first row from the result set. |
| 385 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 386 | .. php:method:: last_row([$type = 'object']) |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 387 | |
| 388 | :param string $type: Type of the requested result - array, object, or class name |
| 389 | :returns: Last row of result set, or NULL if it doesn't exist |
| 390 | :rtype: mixed |
| 391 | |
| 392 | Returns the last row from the result set. |
| 393 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 394 | .. php:method:: num_rows() |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 395 | |
| 396 | :returns: Number of rows in the result set |
| 397 | :rtype: int |
| 398 | |
| 399 | Returns the number of rows in the result set. |
| 400 | |
| 401 | Usage: see `Result Helper Methods`_. |
| 402 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 403 | .. php:method:: num_fields() |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 404 | |
| 405 | :returns: Number of fields in the result set |
| 406 | :rtype: int |
| 407 | |
| 408 | Returns the number of fields in the result set. |
| 409 | |
| 410 | Usage: see `Result Helper Methods`_. |
| 411 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 412 | .. php:method:: field_data() |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 413 | |
| 414 | :returns: Array containing field meta-data |
| 415 | :rtype: array |
| 416 | |
| 417 | Generates an array of ``stdClass`` objects containing |
| 418 | field meta-data. |
James L Parry | 1516219 | 2014-12-05 23:40:47 -0800 | [diff] [blame] | 419 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 420 | .. php:method:: free_result() |
James L Parry | 1516219 | 2014-12-05 23:40:47 -0800 | [diff] [blame] | 421 | |
| 422 | :rtype: void |
| 423 | |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 424 | Frees a result set. |
James L Parry | 1516219 | 2014-12-05 23:40:47 -0800 | [diff] [blame] | 425 | |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 426 | Usage: see `Result Helper Methods`_. |
James L Parry | 1516219 | 2014-12-05 23:40:47 -0800 | [diff] [blame] | 427 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 428 | .. php:method:: list_fields() |
James L Parry | 1516219 | 2014-12-05 23:40:47 -0800 | [diff] [blame] | 429 | |
| 430 | :returns: Array of column names |
| 431 | :rtype: array |
| 432 | |
Andrey Andreev | ab0034b | 2014-12-11 18:31:51 +0200 | [diff] [blame] | 433 | Returns an array containing the field names in the |
| 434 | result set. |