blob: e72d9fa77b5c2d806c663b302e72e34a4bfc0773 [file] [log] [blame]
Derek Jones8ede1a22011-10-05 13:34:52 -05001########################
2Generating Query Results
3########################
4
5There are several ways to generate query results:
6
James L Parry15162192014-12-05 23:40:47 -08007.. contents::
8 :local:
9 :depth: 2
10
James L Parry014bc892014-11-24 17:14:19 -080011*************
12Result Arrays
13*************
14
Andrey Andreevab0034b2014-12-11 18:31:51 +020015**result()**
Derek Jones8ede1a22011-10-05 13:34:52 -050016
James L Parrye4a9f642014-11-24 16:20:53 -080017This method returns the query result as an array of **objects**, or
Derek Jones8ede1a22011-10-05 13:34:52 -050018**an empty array** on failure. Typically you'll use this in a foreach
19loop, like this::
20
Joseph Wensleyf24f4042011-10-06 22:53:29 -040021 $query = $this->db->query("YOUR QUERY");
Andrey Andreev10b6e7a2015-07-24 12:38:58 +030022
Joseph Wensleyf24f4042011-10-06 22:53:29 -040023 foreach ($query->result() as $row)
24 {
25 echo $row->title;
26 echo $row->name;
27 echo $row->body;
28 }
Derek Jones8ede1a22011-10-05 13:34:52 -050029
Andrey Andreevab0034b2014-12-11 18:31:51 +020030The above method is an alias of ``result_object()``.
Derek Jones8ede1a22011-10-05 13:34:52 -050031
32If you run queries that might **not** produce a result, you are
33encouraged to test the result first::
34
Joseph Wensleyf24f4042011-10-06 22:53:29 -040035 $query = $this->db->query("YOUR QUERY");
Lonnie Ezell715959d2015-07-22 09:20:05 -050036
37 foreach ($query->result() as $row)
Joseph Wensleyf24f4042011-10-06 22:53:29 -040038 {
Lonnie Ezell715959d2015-07-22 09:20:05 -050039 echo $row->title;
40 echo $row->name;
41 echo $row->body;
Joseph Wensleyf24f4042011-10-06 22:53:29 -040042 }
Derek Jones8ede1a22011-10-05 13:34:52 -050043
Andrey Andreev10b6e7a2015-07-24 12:38:58 +030044You can also pass a string to ``result()`` which represents a class to
Derek Jones8ede1a22011-10-05 13:34:52 -050045instantiate for each result object (note: this class must be loaded)
46
47::
48
49 $query = $this->db->query("SELECT * FROM users;");
50
51 foreach ($query->result('User') as $user)
52 {
Andrey Andreevab0034b2014-12-11 18:31:51 +020053 echo $user->name; // access attributes
54 echo $user->reverse_name(); // or methods defined on the 'User' class
Derek Jones8ede1a22011-10-05 13:34:52 -050055 }
56
Andrey Andreevab0034b2014-12-11 18:31:51 +020057**result_array()**
Derek Jones8ede1a22011-10-05 13:34:52 -050058
James L Parrye4a9f642014-11-24 16:20:53 -080059This method returns the query result as a pure array, or an empty
Derek Jones8ede1a22011-10-05 13:34:52 -050060array when no result is produced. Typically you'll use this in a foreach
61loop, like this::
62
Joseph Wensleyf24f4042011-10-06 22:53:29 -040063 $query = $this->db->query("YOUR QUERY");
Andrey Andreev10b6e7a2015-07-24 12:38:58 +030064
Joseph Wensleyf24f4042011-10-06 22:53:29 -040065 foreach ($query->result_array() as $row)
66 {
67 echo $row['title'];
68 echo $row['name'];
69 echo $row['body'];
70 }
Derek Jones8ede1a22011-10-05 13:34:52 -050071
James L Parry014bc892014-11-24 17:14:19 -080072***********
73Result Rows
74***********
75
Andrey Andreevab0034b2014-12-11 18:31:51 +020076**row()**
Derek Jones8ede1a22011-10-05 13:34:52 -050077
James L Parrye4a9f642014-11-24 16:20:53 -080078This method returns a single result row. If your query has more than
Derek Jones8ede1a22011-10-05 13:34:52 -050079one row, it returns only the first row. The result is returned as an
80**object**. Here's a usage example::
81
Joseph Wensleyf24f4042011-10-06 22:53:29 -040082 $query = $this->db->query("YOUR QUERY");
Lonnie Ezell715959d2015-07-22 09:20:05 -050083
84 $row = $query->row();
85
Lonnie Ezell752f5692015-07-23 23:27:01 -050086 if (isset($row))
Joseph Wensleyf24f4042011-10-06 22:53:29 -040087 {
Joseph Wensleyf24f4042011-10-06 22:53:29 -040088 echo $row->title;
89 echo $row->name;
90 echo $row->body;
91 }
Derek Jones8ede1a22011-10-05 13:34:52 -050092
93If you want a specific row returned you can submit the row number as a
94digit in the first parameter::
95
96 $row = $query->row(5);
97
98You can also add a second String parameter, which is the name of a class
99to instantiate the row with::
100
Joseph Wensleyf24f4042011-10-06 22:53:29 -0400101 $query = $this->db->query("SELECT * FROM users LIMIT 1;");
sv3tli0d829a5f2015-03-02 17:22:01 +0200102 $row = $query->row(0, 'User');
Joseph Wensleyf24f4042011-10-06 22:53:29 -0400103
Andrey Andreevab0034b2014-12-11 18:31:51 +0200104 echo $row->name; // access attributes
Joseph Wensleyf24f4042011-10-06 22:53:29 -0400105 echo $row->reverse_name(); // or methods defined on the 'User' class
Derek Jones8ede1a22011-10-05 13:34:52 -0500106
Andrey Andreevab0034b2014-12-11 18:31:51 +0200107**row_array()**
Derek Jones8ede1a22011-10-05 13:34:52 -0500108
Andrey Andreevab0034b2014-12-11 18:31:51 +0200109Identical to the above ``row()`` method, except it returns an array.
Derek Jones8ede1a22011-10-05 13:34:52 -0500110Example::
111
Joseph Wensleyf24f4042011-10-06 22:53:29 -0400112 $query = $this->db->query("YOUR QUERY");
Lonnie Ezell715959d2015-07-22 09:20:05 -0500113
114 $row = $query->row_array();
115
Lonnie Ezell752f5692015-07-23 23:27:01 -0500116 if (isset($row))
Joseph Wensleyf24f4042011-10-06 22:53:29 -0400117 {
Joseph Wensleyf24f4042011-10-06 22:53:29 -0400118 echo $row['title'];
119 echo $row['name'];
120 echo $row['body'];
121 }
Derek Jones8ede1a22011-10-05 13:34:52 -0500122
123If you want a specific row returned you can submit the row number as a
124digit in the first parameter::
125
126 $row = $query->row_array(5);
127
128In addition, you can walk forward/backwards/first/last through your
129results using these variations:
130
Joseph Wensleyf24f4042011-10-06 22:53:29 -0400131 | **$row = $query->first_row()**
132 | **$row = $query->last_row()**
133 | **$row = $query->next_row()**
134 | **$row = $query->previous_row()**
Derek Jones8ede1a22011-10-05 13:34:52 -0500135
136By default they return an object unless you put the word "array" in the
137parameter:
138
Joseph Wensleyf24f4042011-10-06 22:53:29 -0400139 | **$row = $query->first_row('array')**
140 | **$row = $query->last_row('array')**
141 | **$row = $query->next_row('array')**
142 | **$row = $query->previous_row('array')**
Derek Jones8ede1a22011-10-05 13:34:52 -0500143
Andrey Andreevab0034b2014-12-11 18:31:51 +0200144.. note:: All the methods above will load the whole result into memory
145 (prefetching). Use ``unbuffered_row()`` for processing large
146 result sets.
Juan Ignacio Bordad981e292012-05-18 18:29:24 -0300147
Andrey Andreevab0034b2014-12-11 18:31:51 +0200148**unbuffered_row()**
Juan Ignacio Bordad981e292012-05-18 18:29:24 -0300149
Andrey Andreev69edc432012-12-04 13:32:16 +0200150This method returns a single result row without prefetching the whole
151result in memory as ``row()`` does. If your query has more than one row,
152it returns the current row and moves the internal data pointer ahead.
Juan Ignacio Bordad981e292012-05-18 18:29:24 -0300153
Derek Jonesce79be02012-06-25 23:23:46 -0700154::
Juan Ignacio Bordad981e292012-05-18 18:29:24 -0300155
156 $query = $this->db->query("YOUR QUERY");
Andrey Andreev10b6e7a2015-07-24 12:38:58 +0300157
Juan Ignacio Bordada7c9e02012-05-19 09:42:40 -0300158 while ($row = $query->unbuffered_row())
Juan Ignacio Bordad981e292012-05-18 18:29:24 -0300159 {
160 echo $row->title;
161 echo $row->name;
162 echo $row->body;
163 }
164
Andrey Andreev69edc432012-12-04 13:32:16 +0200165You can optionally pass 'object' (default) or 'array' in order to specify
166the returned value's type::
167
168 $query->unbuffered_row(); // object
169 $query->unbuffered_row('object'); // object
170 $query->unbuffered_row('array'); // associative array
171
James L Parrye4a9f642014-11-24 16:20:53 -0800172*********************
Lonnie Ezellcf3cc1d2015-07-21 10:22:41 -0500173Custom Result Objects
174*********************
175
Andrey Andreev56d34672015-07-23 14:03:26 +0300176You can have the results returned as an instance of a custom class instead
177of a ``stdClass`` or array, as the ``result()`` and ``result_array()``
178methods allow. This requires that the class is already loaded into memory.
179The object will have all values returned from the database set as properties.
180If these have been declared and are non-public then you should provide a
181``__set()`` method to allow them to be set.
Lonnie Ezellcf3cc1d2015-07-21 10:22:41 -0500182
183Example::
184
185 class User {
Lonnie Ezell25201822015-07-21 21:32:43 -0500186
Andrey Andreev56d34672015-07-23 14:03:26 +0300187 public $id;
188 public $email;
189 public $username;
190
Lonnie Ezellcf3cc1d2015-07-21 10:22:41 -0500191 protected $last_login;
192
193 public function last_login($format)
194 {
Lonnie Ezellabf089a2015-07-22 09:00:37 -0500195 return $this->last_login->format($format);
Lonnie Ezellcf3cc1d2015-07-21 10:22:41 -0500196 }
197
198 public function __set($name, $value)
199 {
Lonnie Ezellabf089a2015-07-22 09:00:37 -0500200 if ($name === 'last_login')
Lonnie Ezellc87a66b2015-07-22 21:48:02 -0500201 {
202 $this->last_login = DateTime::createFromFormat('U', $value);
203 }
Lonnie Ezellcf3cc1d2015-07-21 10:22:41 -0500204 }
205
206 public function __get($name)
207 {
208 if (isset($this->$name))
209 {
210 return $this->$name;
211 }
212 }
213 }
214
Andrey Andreev56d34672015-07-23 14:03:26 +0300215In addition to the two methods listed below, the following methods also can
216take a class name to return the results as: ``first_row()``, ``last_row()``,
217``next_row()``, and ``previous_row()``.
Lonnie Ezellcf3cc1d2015-07-21 10:22:41 -0500218
219**custom_result_object()**
220
Andrey Andreev56d34672015-07-23 14:03:26 +0300221Returns the entire result set as an array of instances of the class requested.
222The only parameter is the name of the class to instantiate.
Lonnie Ezellcf3cc1d2015-07-21 10:22:41 -0500223
224Example::
225
226 $query = $this->db->query("YOUR QUERY");
227
Lonnie Ezell25201822015-07-21 21:32:43 -0500228 $rows = $query->custom_result_object('User');
229
230 foreach ($rows as $row)
Lonnie Ezellcf3cc1d2015-07-21 10:22:41 -0500231 {
Lonnie Ezell25201822015-07-21 21:32:43 -0500232 echo $row->id;
233 echo $row->email;
234 echo $row->last_login('Y-m-d');
Lonnie Ezellcf3cc1d2015-07-21 10:22:41 -0500235 }
236
237**custom_row_object()**
238
Andrey Andreev56d34672015-07-23 14:03:26 +0300239Returns a single row from your query results. The first parameter is the row
240number of the results. The second parameter is the class name to instantiate.
Lonnie Ezellcf3cc1d2015-07-21 10:22:41 -0500241
242Example::
243
244 $query = $this->db->query("YOUR QUERY");
245
Lonnie Ezellc87a66b2015-07-22 21:48:02 -0500246 $row = $query->custom_row_object(0, 'User');
Lonnie Ezellcf3cc1d2015-07-21 10:22:41 -0500247
Andrey Andreev56d34672015-07-23 14:03:26 +0300248 if (isset($row))
Lonnie Ezellc87a66b2015-07-22 21:48:02 -0500249 {
Lonnie Ezellcf3cc1d2015-07-21 10:22:41 -0500250 echo $row->email; // access attributes
251 echo $row->last_login('Y-m-d'); // access class methods
252 }
253
254You can also use the ``row()`` method in exactly the same way.
255
256Example::
257
Lonnie Ezell25201822015-07-21 21:32:43 -0500258 $row = $query->custom_row_object(0, 'User');
Lonnie Ezellcf3cc1d2015-07-21 10:22:41 -0500259
260*********************
James L Parrye4a9f642014-11-24 16:20:53 -0800261Result Helper Methods
262*********************
Derek Jones8ede1a22011-10-05 13:34:52 -0500263
Andrey Andreevab0034b2014-12-11 18:31:51 +0200264**num_rows()**
Derek Jones8ede1a22011-10-05 13:34:52 -0500265
266The number of rows returned by the query. Note: In this example, $query
267is the variable that the query result object is assigned to::
268
Joseph Wensleyf24f4042011-10-06 22:53:29 -0400269 $query = $this->db->query('SELECT * FROM my_table');
Andrey Andreev10b6e7a2015-07-24 12:38:58 +0300270
Joseph Wensleyf24f4042011-10-06 22:53:29 -0400271 echo $query->num_rows();
Derek Jones8ede1a22011-10-05 13:34:52 -0500272
Andrey Andreevab0034b2014-12-11 18:31:51 +0200273.. note:: Not all database drivers have a native way of getting the total
Andrey Andreevfdb75412012-03-05 16:32:17 +0200274 number of rows for a result set. When this is the case, all of
Andrey Andreevab0034b2014-12-11 18:31:51 +0200275 the data is prefetched and ``count()`` is manually called on the
276 resulting array in order to achieve the same result.
Andrey Andreevfdb75412012-03-05 16:32:17 +0200277
Andrey Andreevab0034b2014-12-11 18:31:51 +0200278**num_fields()**
Derek Jones8ede1a22011-10-05 13:34:52 -0500279
280The number of FIELDS (columns) returned by the query. Make sure to call
James L Parrye4a9f642014-11-24 16:20:53 -0800281the method using your query result object::
Derek Jones8ede1a22011-10-05 13:34:52 -0500282
Joseph Wensleyf24f4042011-10-06 22:53:29 -0400283 $query = $this->db->query('SELECT * FROM my_table');
Andrey Andreev10b6e7a2015-07-24 12:38:58 +0300284
Joseph Wensleyf24f4042011-10-06 22:53:29 -0400285 echo $query->num_fields();
Derek Jones8ede1a22011-10-05 13:34:52 -0500286
Andrey Andreevab0034b2014-12-11 18:31:51 +0200287**free_result()**
Derek Jones8ede1a22011-10-05 13:34:52 -0500288
289It frees the memory associated with the result and deletes the result
290resource ID. Normally PHP frees its memory automatically at the end of
291script execution. However, if you are running a lot of queries in a
292particular script you might want to free the result after each query
Andrey Andreevab0034b2014-12-11 18:31:51 +0200293result has been generated in order to cut down on memory consumption.
294
Derek Jones8ede1a22011-10-05 13:34:52 -0500295Example::
296
Joseph Wensleyf24f4042011-10-06 22:53:29 -0400297 $query = $this->db->query('SELECT title FROM my_table');
Andrey Andreev10b6e7a2015-07-24 12:38:58 +0300298
Joseph Wensleyf24f4042011-10-06 22:53:29 -0400299 foreach ($query->result() as $row)
300 {
301 echo $row->title;
302 }
Andrey Andreevab0034b2014-12-11 18:31:51 +0200303
Joseph Wensleyf24f4042011-10-06 22:53:29 -0400304 $query->free_result(); // The $query result object will no longer be available
305
306 $query2 = $this->db->query('SELECT name FROM some_table');
307
308 $row = $query2->row();
309 echo $row->name;
Andrey Andreevfdb75412012-03-05 16:32:17 +0200310 $query2->free_result(); // The $query2 result object will no longer be available
Andrey Andreev69edc432012-12-04 13:32:16 +0200311
James L Parrye4a9f642014-11-24 16:20:53 -0800312**data_seek()**
Andrey Andreev69edc432012-12-04 13:32:16 +0200313
314This method sets the internal pointer for the next result row to be
315fetched. It is only useful in combination with ``unbuffered_row()``.
316
317It accepts a positive integer value, which defaults to 0 and returns
318TRUE on success or FALSE on failure.
319
320::
321
322 $query = $this->db->query('SELECT `field_name` FROM `table_name`');
323 $query->data_seek(5); // Skip the first 5 rows
324 $row = $query->unbuffered_row();
325
326.. note:: Not all database drivers support this feature and will return FALSE.
James L Parry15162192014-12-05 23:40:47 -0800327 Most notably - you won't be able to use it with PDO.
328
329***************
330Class Reference
331***************
332
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200333.. php:class:: CI_DB_result
James L Parry15162192014-12-05 23:40:47 -0800334
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200335 .. php:method:: result([$type = 'object'])
Andrey Andreevab0034b2014-12-11 18:31:51 +0200336
337 :param string $type: Type of requested results - array, object, or class name
338 :returns: Array containing the fetched rows
339 :rtype: array
340
341 A wrapper for the ``result_array()``, ``result_object()``
342 and ``custom_result_object()`` methods.
343
344 Usage: see `Result Arrays`_.
345
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200346 .. php:method:: result_array()
Andrey Andreevab0034b2014-12-11 18:31:51 +0200347
348 :returns: Array containing the fetched rows
349 :rtype: array
350
351 Returns the query results as an array of rows, where each
352 row is itself an associative array.
353
354 Usage: see `Result Arrays`_.
355
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200356 .. php:method:: result_object()
Andrey Andreevab0034b2014-12-11 18:31:51 +0200357
358 :returns: Array containing the fetched rows
359 :rtype: array
360
361 Returns the query results as an array of rows, where each
362 row is an object of type ``stdClass``.
363
364 Usage: see `Result Arrays`_.
365
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200366 .. php:method:: custom_result_object($class_name)
James L Parry15162192014-12-05 23:40:47 -0800367
Andrey Andreevab0034b2014-12-11 18:31:51 +0200368 :param string $class_name: Class name for the resulting rows
369 :returns: Array containing the fetched rows
370 :rtype: array
James L Parry15162192014-12-05 23:40:47 -0800371
Andrey Andreevab0034b2014-12-11 18:31:51 +0200372 Returns the query results as an array of rows, where each
373 row is an instance of the specified class.
374
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200375 .. php:method:: row([$n = 0[, $type = 'object']])
Andrey Andreevab0034b2014-12-11 18:31:51 +0200376
377 :param int $n: Index of the query results row to be returned
378 :param string $type: Type of the requested result - array, object, or class name
379 :returns: The requested row or NULL if it doesn't exist
380 :rtype: mixed
381
382 A wrapper for the ``row_array()``, ``row_object() and
383 ``custom_row_object()`` methods.
384
385 Usage: see `Result Rows`_.
386
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200387 .. php:method:: unbuffered_row([$type = 'object'])
Andrey Andreevab0034b2014-12-11 18:31:51 +0200388
389 :param string $type: Type of the requested result - array, object, or class name
390 :returns: Next row from the result set or NULL if it doesn't exist
391 :rtype: mixed
392
393 Fetches the next result row and returns it in the
394 requested form.
395
396 Usage: see `Result Rows`_.
397
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200398 .. php:method:: row_array([$n = 0])
Andrey Andreevab0034b2014-12-11 18:31:51 +0200399
400 :param int $n: Index of the query results row to be returned
401 :returns: The requested row or NULL if it doesn't exist
402 :rtype: array
403
404 Returns the requested result row as an associative array.
405
406 Usage: see `Result Rows`_.
407
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200408 .. php:method:: row_object([$n = 0])
Andrey Andreevab0034b2014-12-11 18:31:51 +0200409
410 :param int $n: Index of the query results row to be returned
411 :returns: The requested row or NULL if it doesn't exist
412 :rtype: stdClass
413
414 Returns the requested result row as an object of type
415 ``stdClass``.
416
417 Usage: see `Result Rows`_.
James L Parry15162192014-12-05 23:40:47 -0800418
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200419 .. php:method:: custom_row_object($n, $type)
James L Parry15162192014-12-05 23:40:47 -0800420
421 :param int $n: Index of the results row to return
Andrey Andreevab0034b2014-12-11 18:31:51 +0200422 :param string $class_name: Class name for the resulting row
423 :returns: The requested row or NULL if it doesn't exist
James L Parry15162192014-12-05 23:40:47 -0800424 :rtype: $type
425
Andrey Andreevab0034b2014-12-11 18:31:51 +0200426 Returns the requested result row as an instance of the
427 requested class.
James L Parry15162192014-12-05 23:40:47 -0800428
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200429 .. php:method:: data_seek([$n = 0])
James L Parry15162192014-12-05 23:40:47 -0800430
431 :param int $n: Index of the results row to be returned next
Andrey Andreevab0034b2014-12-11 18:31:51 +0200432 :returns: TRUE on success, FALSE on failure
James L Parry15162192014-12-05 23:40:47 -0800433 :rtype: bool
434
435 Moves the internal results row pointer to the desired offset.
James L Parry15162192014-12-05 23:40:47 -0800436
Andrey Andreevab0034b2014-12-11 18:31:51 +0200437 Usage: see `Result Helper Methods`_.
James L Parry15162192014-12-05 23:40:47 -0800438
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200439 .. php:method:: set_row($key[, $value = NULL])
James L Parry15162192014-12-05 23:40:47 -0800440
Andrey Andreevab0034b2014-12-11 18:31:51 +0200441 :param mixed $key: Column name or array of key/value pairs
442 :param mixed $value: Value to assign to the column, $key is a single field name
443 :rtype: void
444
445 Assigns a value to a particular column.
446
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200447 .. php:method:: next_row([$type = 'object'])
Andrey Andreevab0034b2014-12-11 18:31:51 +0200448
449 :param string $type: Type of the requested result - array, object, or class name
450 :returns: Next row of result set, or NULL if it doesn't exist
451 :rtype: mixed
452
453 Returns the next row from the result set.
454
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200455 .. php:method:: previous_row([$type = 'object'])
Andrey Andreevab0034b2014-12-11 18:31:51 +0200456
457 :param string $type: Type of the requested result - array, object, or class name
458 :returns: Previous row of result set, or NULL if it doesn't exist
459 :rtype: mixed
460
461 Returns the previous row from the result set.
James L Parry15162192014-12-05 23:40:47 -0800462
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200463 .. php:method:: first_row([$type = 'object'])
James L Parry15162192014-12-05 23:40:47 -0800464
Andrey Andreevab0034b2014-12-11 18:31:51 +0200465 :param string $type: Type of the requested result - array, object, or class name
466 :returns: First row of result set, or NULL if it doesn't exist
James L Parry15162192014-12-05 23:40:47 -0800467 :rtype: mixed
468
Andrey Andreevab0034b2014-12-11 18:31:51 +0200469 Returns the first row from the result set.
470
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200471 .. php:method:: last_row([$type = 'object'])
Andrey Andreevab0034b2014-12-11 18:31:51 +0200472
473 :param string $type: Type of the requested result - array, object, or class name
474 :returns: Last row of result set, or NULL if it doesn't exist
475 :rtype: mixed
476
477 Returns the last row from the result set.
478
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200479 .. php:method:: num_rows()
Andrey Andreevab0034b2014-12-11 18:31:51 +0200480
481 :returns: Number of rows in the result set
482 :rtype: int
483
484 Returns the number of rows in the result set.
485
486 Usage: see `Result Helper Methods`_.
487
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200488 .. php:method:: num_fields()
Andrey Andreevab0034b2014-12-11 18:31:51 +0200489
490 :returns: Number of fields in the result set
491 :rtype: int
492
493 Returns the number of fields in the result set.
494
495 Usage: see `Result Helper Methods`_.
496
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200497 .. php:method:: field_data()
Andrey Andreevab0034b2014-12-11 18:31:51 +0200498
499 :returns: Array containing field meta-data
500 :rtype: array
501
502 Generates an array of ``stdClass`` objects containing
503 field meta-data.
James L Parry15162192014-12-05 23:40:47 -0800504
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200505 .. php:method:: free_result()
James L Parry15162192014-12-05 23:40:47 -0800506
507 :rtype: void
508
Andrey Andreevab0034b2014-12-11 18:31:51 +0200509 Frees a result set.
James L Parry15162192014-12-05 23:40:47 -0800510
Andrey Andreevab0034b2014-12-11 18:31:51 +0200511 Usage: see `Result Helper Methods`_.
James L Parry15162192014-12-05 23:40:47 -0800512
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200513 .. php:method:: list_fields()
James L Parry15162192014-12-05 23:40:47 -0800514
515 :returns: Array of column names
516 :rtype: array
517
Andrey Andreevab0034b2014-12-11 18:31:51 +0200518 Returns an array containing the field names in the
sv3tli0d829a5f2015-03-02 17:22:01 +0200519 result set.