blob: 6b03d2255a5c4c0d51cb4273f4eda1ae055f3c59 [file] [log] [blame]
Andrey Andreevc5769952019-01-16 17:49:35 +02001
2
3<!DOCTYPE html>
4<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
5<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
6<head>
7 <meta charset="utf-8">
8 <meta name="viewport" content="width=device-width, initial-scale=1.0">
9
10 <title>Generating Query Results &mdash; CodeIgniter 3.1.10 documentation</title>
11
12
13
14
15 <link rel="shortcut icon" href="../_static/ci-icon.ico"/>
16
17
18
19 <link href='https://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic|Roboto+Slab:400,700|Inconsolata:400,700&subset=latin,cyrillic' rel='stylesheet' type='text/css'>
20
21
22
23
24
25
26
27
28
29 <link rel="stylesheet" href="../_static/css/citheme.css" type="text/css" />
30
31
32
33 <link rel="index" title="Index"
34 href="../genindex.html"/>
35 <link rel="search" title="Search" href="../search.html"/>
36 <link rel="top" title="CodeIgniter 3.1.10 documentation" href="../index.html"/>
37 <link rel="up" title="Database Reference" href="index.html"/>
38 <link rel="next" title="Query Helper Methods" href="helpers.html"/>
39 <link rel="prev" title="Queries" href="queries.html"/>
40
41
42 <script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"></script>
43
44</head>
45
46<body class="wy-body-for-nav" role="document">
47
48 <div id="nav">
49 <div id="nav_inner">
50
51
52
53 <div id="pulldown-menu" class="ciNav">
54 <ul>
55<li class="toctree-l1"><a class="reference internal" href="../general/welcome.html">Welcome to CodeIgniter</a></li>
56</ul>
57<ul>
58<li class="toctree-l1"><a class="reference internal" href="../installation/index.html">Installation Instructions</a><ul>
59<li class="toctree-l2"><a class="reference internal" href="../installation/downloads.html">Downloading CodeIgniter</a></li>
60<li class="toctree-l2"><a class="reference internal" href="../installation/index.html">Installation Instructions</a></li>
61<li class="toctree-l2"><a class="reference internal" href="../installation/upgrading.html">Upgrading From a Previous Version</a></li>
62<li class="toctree-l2"><a class="reference internal" href="../installation/troubleshooting.html">Troubleshooting</a></li>
63</ul>
64</li>
65</ul>
66<ul>
67<li class="toctree-l1"><a class="reference internal" href="../overview/index.html">CodeIgniter Overview</a><ul>
68<li class="toctree-l2"><a class="reference internal" href="../overview/getting_started.html">Getting Started</a></li>
69<li class="toctree-l2"><a class="reference internal" href="../overview/at_a_glance.html">CodeIgniter at a Glance</a></li>
70<li class="toctree-l2"><a class="reference internal" href="../overview/features.html">Supported Features</a></li>
71<li class="toctree-l2"><a class="reference internal" href="../overview/appflow.html">Application Flow Chart</a></li>
72<li class="toctree-l2"><a class="reference internal" href="../overview/mvc.html">Model-View-Controller</a></li>
73<li class="toctree-l2"><a class="reference internal" href="../overview/goals.html">Architectural Goals</a></li>
74</ul>
75</li>
76</ul>
77<ul>
78<li class="toctree-l1"><a class="reference internal" href="../tutorial/index.html">Tutorial</a><ul>
79<li class="toctree-l2"><a class="reference internal" href="../tutorial/static_pages.html">Static pages</a></li>
80<li class="toctree-l2"><a class="reference internal" href="../tutorial/news_section.html">News section</a></li>
81<li class="toctree-l2"><a class="reference internal" href="../tutorial/create_news_items.html">Create news items</a></li>
82<li class="toctree-l2"><a class="reference internal" href="../tutorial/conclusion.html">Conclusion</a></li>
83</ul>
84</li>
85</ul>
86<ul>
87<li class="toctree-l1"><a class="reference internal" href="../contributing/index.html">Contributing to CodeIgniter</a><ul>
88<li class="toctree-l2"><a class="reference internal" href="../documentation/index.html">Writing CodeIgniter Documentation</a></li>
89<li class="toctree-l2"><a class="reference internal" href="../DCO.html">Developer’s Certificate of Origin 1.1</a></li>
90</ul>
91</li>
92</ul>
93<ul>
94<li class="toctree-l1"><a class="reference internal" href="../general/index.html">General Topics</a><ul>
95<li class="toctree-l2"><a class="reference internal" href="../general/urls.html">CodeIgniter URLs</a></li>
96<li class="toctree-l2"><a class="reference internal" href="../general/controllers.html">Controllers</a></li>
97<li class="toctree-l2"><a class="reference internal" href="../general/reserved_names.html">Reserved Names</a></li>
98<li class="toctree-l2"><a class="reference internal" href="../general/views.html">Views</a></li>
99<li class="toctree-l2"><a class="reference internal" href="../general/models.html">Models</a></li>
100<li class="toctree-l2"><a class="reference internal" href="../general/helpers.html">Helpers</a></li>
101<li class="toctree-l2"><a class="reference internal" href="../general/libraries.html">Using CodeIgniter Libraries</a></li>
102<li class="toctree-l2"><a class="reference internal" href="../general/creating_libraries.html">Creating Libraries</a></li>
103<li class="toctree-l2"><a class="reference internal" href="../general/drivers.html">Using CodeIgniter Drivers</a></li>
104<li class="toctree-l2"><a class="reference internal" href="../general/creating_drivers.html">Creating Drivers</a></li>
105<li class="toctree-l2"><a class="reference internal" href="../general/core_classes.html">Creating Core System Classes</a></li>
106<li class="toctree-l2"><a class="reference internal" href="../general/ancillary_classes.html">Creating Ancillary Classes</a></li>
107<li class="toctree-l2"><a class="reference internal" href="../general/hooks.html">Hooks - Extending the Framework Core</a></li>
108<li class="toctree-l2"><a class="reference internal" href="../general/autoloader.html">Auto-loading Resources</a></li>
109<li class="toctree-l2"><a class="reference internal" href="../general/common_functions.html">Common Functions</a></li>
110<li class="toctree-l2"><a class="reference internal" href="../general/compatibility_functions.html">Compatibility Functions</a></li>
111<li class="toctree-l2"><a class="reference internal" href="../general/routing.html">URI Routing</a></li>
112<li class="toctree-l2"><a class="reference internal" href="../general/errors.html">Error Handling</a></li>
113<li class="toctree-l2"><a class="reference internal" href="../general/caching.html">Caching</a></li>
114<li class="toctree-l2"><a class="reference internal" href="../general/profiling.html">Profiling Your Application</a></li>
115<li class="toctree-l2"><a class="reference internal" href="../general/cli.html">Running via the CLI</a></li>
116<li class="toctree-l2"><a class="reference internal" href="../general/managing_apps.html">Managing your Applications</a></li>
117<li class="toctree-l2"><a class="reference internal" href="../general/environments.html">Handling Multiple Environments</a></li>
118<li class="toctree-l2"><a class="reference internal" href="../general/alternative_php.html">Alternate PHP Syntax for View Files</a></li>
119<li class="toctree-l2"><a class="reference internal" href="../general/security.html">Security</a></li>
120<li class="toctree-l2"><a class="reference internal" href="../general/styleguide.html">PHP Style Guide</a></li>
121</ul>
122</li>
123</ul>
124<ul>
125<li class="toctree-l1"><a class="reference internal" href="../libraries/index.html">Libraries</a><ul>
126<li class="toctree-l2"><a class="reference internal" href="../libraries/benchmark.html">Benchmarking Class</a></li>
127<li class="toctree-l2"><a class="reference internal" href="../libraries/caching.html">Caching Driver</a></li>
128<li class="toctree-l2"><a class="reference internal" href="../libraries/calendar.html">Calendaring Class</a></li>
129<li class="toctree-l2"><a class="reference internal" href="../libraries/cart.html">Shopping Cart Class</a></li>
130<li class="toctree-l2"><a class="reference internal" href="../libraries/config.html">Config Class</a></li>
131<li class="toctree-l2"><a class="reference internal" href="../libraries/email.html">Email Class</a></li>
132<li class="toctree-l2"><a class="reference internal" href="../libraries/encrypt.html">Encrypt Class</a></li>
133<li class="toctree-l2"><a class="reference internal" href="../libraries/encryption.html">Encryption Library</a></li>
134<li class="toctree-l2"><a class="reference internal" href="../libraries/file_uploading.html">File Uploading Class</a></li>
135<li class="toctree-l2"><a class="reference internal" href="../libraries/form_validation.html">Form Validation</a></li>
136<li class="toctree-l2"><a class="reference internal" href="../libraries/ftp.html">FTP Class</a></li>
137<li class="toctree-l2"><a class="reference internal" href="../libraries/image_lib.html">Image Manipulation Class</a></li>
138<li class="toctree-l2"><a class="reference internal" href="../libraries/input.html">Input Class</a></li>
139<li class="toctree-l2"><a class="reference internal" href="../libraries/javascript.html">Javascript Class</a></li>
140<li class="toctree-l2"><a class="reference internal" href="../libraries/language.html">Language Class</a></li>
141<li class="toctree-l2"><a class="reference internal" href="../libraries/loader.html">Loader Class</a></li>
142<li class="toctree-l2"><a class="reference internal" href="../libraries/migration.html">Migrations Class</a></li>
143<li class="toctree-l2"><a class="reference internal" href="../libraries/output.html">Output Class</a></li>
144<li class="toctree-l2"><a class="reference internal" href="../libraries/pagination.html">Pagination Class</a></li>
145<li class="toctree-l2"><a class="reference internal" href="../libraries/parser.html">Template Parser Class</a></li>
146<li class="toctree-l2"><a class="reference internal" href="../libraries/security.html">Security Class</a></li>
147<li class="toctree-l2"><a class="reference internal" href="../libraries/sessions.html">Session Library</a></li>
148<li class="toctree-l2"><a class="reference internal" href="../libraries/table.html">HTML Table Class</a></li>
149<li class="toctree-l2"><a class="reference internal" href="../libraries/trackback.html">Trackback Class</a></li>
150<li class="toctree-l2"><a class="reference internal" href="../libraries/typography.html">Typography Class</a></li>
151<li class="toctree-l2"><a class="reference internal" href="../libraries/unit_testing.html">Unit Testing Class</a></li>
152<li class="toctree-l2"><a class="reference internal" href="../libraries/uri.html">URI Class</a></li>
153<li class="toctree-l2"><a class="reference internal" href="../libraries/user_agent.html">User Agent Class</a></li>
154<li class="toctree-l2"><a class="reference internal" href="../libraries/xmlrpc.html">XML-RPC and XML-RPC Server Classes</a></li>
155<li class="toctree-l2"><a class="reference internal" href="../libraries/zip.html">Zip Encoding Class</a></li>
156</ul>
157</li>
158</ul>
159<ul class="current">
160<li class="toctree-l1 current"><a class="reference internal" href="index.html">Database Reference</a><ul class="current">
161<li class="toctree-l2"><a class="reference internal" href="examples.html">Quick Start: Usage Examples</a></li>
162<li class="toctree-l2"><a class="reference internal" href="configuration.html">Database Configuration</a></li>
163<li class="toctree-l2"><a class="reference internal" href="connecting.html">Connecting to a Database</a></li>
164<li class="toctree-l2"><a class="reference internal" href="queries.html">Running Queries</a></li>
165<li class="toctree-l2 current"><a class="current reference internal" href="#">Generating Query Results</a></li>
166<li class="toctree-l2"><a class="reference internal" href="helpers.html">Query Helper Functions</a></li>
167<li class="toctree-l2"><a class="reference internal" href="query_builder.html">Query Builder Class</a></li>
168<li class="toctree-l2"><a class="reference internal" href="transactions.html">Transactions</a></li>
169<li class="toctree-l2"><a class="reference internal" href="metadata.html">Getting MetaData</a></li>
170<li class="toctree-l2"><a class="reference internal" href="call_function.html">Custom Function Calls</a></li>
171<li class="toctree-l2"><a class="reference internal" href="caching.html">Query Caching</a></li>
172<li class="toctree-l2"><a class="reference internal" href="forge.html">Database Manipulation with Database Forge</a></li>
173<li class="toctree-l2"><a class="reference internal" href="utilities.html">Database Utilities Class</a></li>
174<li class="toctree-l2"><a class="reference internal" href="db_driver_reference.html">Database Driver Reference</a></li>
175</ul>
176</li>
177</ul>
178<ul>
179<li class="toctree-l1"><a class="reference internal" href="../helpers/index.html">Helpers</a><ul>
180<li class="toctree-l2"><a class="reference internal" href="../helpers/array_helper.html">Array Helper</a></li>
181<li class="toctree-l2"><a class="reference internal" href="../helpers/captcha_helper.html">CAPTCHA Helper</a></li>
182<li class="toctree-l2"><a class="reference internal" href="../helpers/cookie_helper.html">Cookie Helper</a></li>
183<li class="toctree-l2"><a class="reference internal" href="../helpers/date_helper.html">Date Helper</a></li>
184<li class="toctree-l2"><a class="reference internal" href="../helpers/directory_helper.html">Directory Helper</a></li>
185<li class="toctree-l2"><a class="reference internal" href="../helpers/download_helper.html">Download Helper</a></li>
186<li class="toctree-l2"><a class="reference internal" href="../helpers/email_helper.html">Email Helper</a></li>
187<li class="toctree-l2"><a class="reference internal" href="../helpers/file_helper.html">File Helper</a></li>
188<li class="toctree-l2"><a class="reference internal" href="../helpers/form_helper.html">Form Helper</a></li>
189<li class="toctree-l2"><a class="reference internal" href="../helpers/html_helper.html">HTML Helper</a></li>
190<li class="toctree-l2"><a class="reference internal" href="../helpers/inflector_helper.html">Inflector Helper</a></li>
191<li class="toctree-l2"><a class="reference internal" href="../helpers/language_helper.html">Language Helper</a></li>
192<li class="toctree-l2"><a class="reference internal" href="../helpers/number_helper.html">Number Helper</a></li>
193<li class="toctree-l2"><a class="reference internal" href="../helpers/path_helper.html">Path Helper</a></li>
194<li class="toctree-l2"><a class="reference internal" href="../helpers/security_helper.html">Security Helper</a></li>
195<li class="toctree-l2"><a class="reference internal" href="../helpers/smiley_helper.html">Smiley Helper</a></li>
196<li class="toctree-l2"><a class="reference internal" href="../helpers/string_helper.html">String Helper</a></li>
197<li class="toctree-l2"><a class="reference internal" href="../helpers/text_helper.html">Text Helper</a></li>
198<li class="toctree-l2"><a class="reference internal" href="../helpers/typography_helper.html">Typography Helper</a></li>
199<li class="toctree-l2"><a class="reference internal" href="../helpers/url_helper.html">URL Helper</a></li>
200<li class="toctree-l2"><a class="reference internal" href="../helpers/xml_helper.html">XML Helper</a></li>
201</ul>
202</li>
203</ul>
204
205 </div>
206
207
208 </div>
209</div>
210<div id="nav2">
211 <a href="#" id="openToc">
212 <img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAgAAZABkAAD/7AARRHVja3kAAQAEAAAARgAA/+4ADkFkb2JlAGTAAAAAAf/bAIQABAMDAwMDBAMDBAYEAwQGBwUEBAUHCAYGBwYGCAoICQkJCQgKCgwMDAwMCgwMDQ0MDBERERERFBQUFBQUFBQUFAEEBQUIBwgPCgoPFA4ODhQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU/8AAEQgAKwCaAwERAAIRAQMRAf/EAHsAAQAABwEBAAAAAAAAAAAAAAABAwQFBgcIAgkBAQAAAAAAAAAAAAAAAAAAAAAQAAEDAwICBwYEAgsAAAAAAAIBAwQAEQUSBiEHkROTVNQWGDFBUVIUCHEiMtOUFWGBobHRQlMkZIRVEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwDSC+ygkOOaUoKigUCgUCgUCgUCgUCgUCgUCgkuGguIP9FBMFb0Hqg7We+3jlmIqqYFf4ub+/QYlnOR/LqIBKGFUbf8qWv971BytQXXE7Y3Lnm3HsFhp2TaZJAdchRXpIgSpdEJWxJEW3xoKV7F5OMy7JkQn2o7D6w33XGjEAkoiqrJEqIiOIiKuhePCgqp22dyYyS3CyWHnQ5joG61HkRnmnTbaFSMhExRVQRRVJU9iUHjE7ez+fJ0MFipmUNhBV8YUd2SoIV9KkjQla9ltegttBdPLW4/qocL+UTfrMiHW4+P9M71shuyrqaHTcxsl7jegpsji8nh5ZwMvDfgTm0RTjSmjYdFCS6KoOIipdFunCgmNYTMv457MMY6U7iI6oMieDDhRm1VbIhuoOkbqtuK0Hpzb+eZcYZexUxt6UyUqK2cd0SdjtgrhOgijcgERUlJOCIl6CpgbP3blRI8XgMjNARAyKNDfeRBdFDBVUAXgQrqH4pxoJTu2NysY97LP4ac1io5q1InHFeGO24LnVKJuKOkSQ/yKir+rh7aCLG1dzypZQI2FnvTgccYOM3FeN0XWERXAUEFVQgQkUktdLpegm+Td3/Xli/L+S/mYNJIOF9G/wBeLKrZHFb0akG6W1WtQWSg3Dyg5e7V3fipE3O4/wCrktyzYA+ufas2LbZIlmnAT2kvuoN1wft95augilglX/tzP3qCu9O3LL/wV/i5v79BvmTADq14UGu91467Z6U9y0HzH/ncj/U/sT/CgynZG7I2NezpZGUjIycJkYkZSG+uQ81pbBNKLxJfjwoMqZ3/ALYHl35AJ7/cuwHcu5k7r1Q5pHetBjquqVVJWGxj9Zrtcl/Ggy3dHMvauR3HFZj5nHNxSyW5JISYDMoIwx8tFIGHZhPNaykGapr6rUAiicEoMG21lMRj8buPAz8xhJrr7uOeiPTCyAwXUaGR1mgozbTusOsFLEiJ7fbQa/h7gcjy2H3V6xppwDNtUSxCJIqp7valBuWVzJ22xuCROXNNZiJkMtms0DbjUkAZjzoDrTMd9dDRI44ZC2YsrYdKWP2WDT2S3N9dNdlRYrGMYc06IURXSYb0igrpWS485xVNS6nF4rwslkoMwnbpgZLB7bmt5uMweAhDEl4B5uSLzzqTnnyVpW2jaJHRMSIjdDiiotvy3DOE5rYTEbkl5yFn28k7JyG4c7AU2HtLH1uKfaiMPI40CdYbpNtmLdwTSn5rewLNld+7TLdeal4WarWBkbVKBjgdElMJJwAAY5fl4kB3b1fp4XvagsGS3FjJfLzDNtS8aeXx7LzT7TyzByQE5PccRGRC0ZRUDRV6y62vbjagzLmJzS2vuPK43JY6aP1TW6Jz+RIWyFtyC06y3EkiiinAo7YCqfq1AqqnGgsOH3lhZO8d1pmcpB8j5XIm9OYlBJSQ/FSS4427DKO0RC8AlcEMhFdViRR1WDWR5t3WXVuL1d106kG9vdeye2g60+1FDyW0shIcXVpyroXt8I8dfd+NB1vioAdWnD3UF1+gD4UFc6CEKpagxXN43rwJLUHz7yX2c8zokt9uHlsPIhA4aRnnHJTLptIS6CNsY7iASpxUUMkReGpfbQW0vtN5pitvrsN28rwtBD0nc0+/Yft5XhaB6TuaXfsP28rwtA9J3NPv2H7eV4Wgek7mn37D9vK8LQPSdzT79h+3leFoHpO5pd+w/byvC0D0nc0u/Yft5XhaB6TuaXfsP28rwtA9J3NLv2H7eV4Wgek7ml37D9vK8LQPSdzS79h+3leFoHpO5p9+w/byvC0E9r7Reazy2HIYVPxkS/CUHVn26cosxyv2g7h89LYmZSXOenvLEQ1YaQ222RATcQCP8rSGqqA8S02W2pQ6FhMoAIlqCtsnwoCpdKClejI4i3Sgtb+GBxVuNBSFt1pV/RQefLjPyUDy4z8lA8uM/JQPLjPyUDy4z8lA8uM/JQPLjPyUDy4z8lA8uM/JQPLjPyUDy4z8lA8utJ/koJ7WCbBU/LQXOPAFq1koK8B0pag90CggtBBf6qB0UDooHRQOigdFA6KB0UDooHRQOigdFA6KB0UDooI0EaBQf//Z" title="Toggle Table of Contents" alt="Toggle Table of Contents" />
213 </a>
214</div>
215
216 <div class="wy-grid-for-nav">
217
218
219 <nav data-toggle="wy-nav-shift" class="wy-nav-side">
220 <div class="wy-side-nav-search">
221
222 <a href="../index.html" class="fa fa-home"> CodeIgniter</a>
223
224
225<div role="search">
226 <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
227 <input type="text" name="q" placeholder="Search docs" />
228 <input type="hidden" name="check_keywords" value="yes" />
229 <input type="hidden" name="area" value="default" />
230 </form>
231</div>
232 </div>
233
234 <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
235
236
237
238 <ul>
239<li class="toctree-l1"><a class="reference internal" href="../general/welcome.html">Welcome to CodeIgniter</a></li>
240</ul>
241<ul>
242<li class="toctree-l1"><a class="reference internal" href="../installation/index.html">Installation Instructions</a><ul>
243<li class="toctree-l2"><a class="reference internal" href="../installation/downloads.html">Downloading CodeIgniter</a></li>
244<li class="toctree-l2"><a class="reference internal" href="../installation/index.html">Installation Instructions</a></li>
245<li class="toctree-l2"><a class="reference internal" href="../installation/upgrading.html">Upgrading From a Previous Version</a></li>
246<li class="toctree-l2"><a class="reference internal" href="../installation/troubleshooting.html">Troubleshooting</a></li>
247</ul>
248</li>
249</ul>
250<ul>
251<li class="toctree-l1"><a class="reference internal" href="../overview/index.html">CodeIgniter Overview</a><ul>
252<li class="toctree-l2"><a class="reference internal" href="../overview/getting_started.html">Getting Started</a></li>
253<li class="toctree-l2"><a class="reference internal" href="../overview/at_a_glance.html">CodeIgniter at a Glance</a></li>
254<li class="toctree-l2"><a class="reference internal" href="../overview/features.html">Supported Features</a></li>
255<li class="toctree-l2"><a class="reference internal" href="../overview/appflow.html">Application Flow Chart</a></li>
256<li class="toctree-l2"><a class="reference internal" href="../overview/mvc.html">Model-View-Controller</a></li>
257<li class="toctree-l2"><a class="reference internal" href="../overview/goals.html">Architectural Goals</a></li>
258</ul>
259</li>
260</ul>
261<ul>
262<li class="toctree-l1"><a class="reference internal" href="../tutorial/index.html">Tutorial</a><ul>
263<li class="toctree-l2"><a class="reference internal" href="../tutorial/static_pages.html">Static pages</a></li>
264<li class="toctree-l2"><a class="reference internal" href="../tutorial/news_section.html">News section</a></li>
265<li class="toctree-l2"><a class="reference internal" href="../tutorial/create_news_items.html">Create news items</a></li>
266<li class="toctree-l2"><a class="reference internal" href="../tutorial/conclusion.html">Conclusion</a></li>
267</ul>
268</li>
269</ul>
270<ul>
271<li class="toctree-l1"><a class="reference internal" href="../contributing/index.html">Contributing to CodeIgniter</a><ul>
272<li class="toctree-l2"><a class="reference internal" href="../documentation/index.html">Writing CodeIgniter Documentation</a></li>
273<li class="toctree-l2"><a class="reference internal" href="../DCO.html">Developer’s Certificate of Origin 1.1</a></li>
274</ul>
275</li>
276</ul>
277<ul>
278<li class="toctree-l1"><a class="reference internal" href="../general/index.html">General Topics</a><ul>
279<li class="toctree-l2"><a class="reference internal" href="../general/urls.html">CodeIgniter URLs</a></li>
280<li class="toctree-l2"><a class="reference internal" href="../general/controllers.html">Controllers</a></li>
281<li class="toctree-l2"><a class="reference internal" href="../general/reserved_names.html">Reserved Names</a></li>
282<li class="toctree-l2"><a class="reference internal" href="../general/views.html">Views</a></li>
283<li class="toctree-l2"><a class="reference internal" href="../general/models.html">Models</a></li>
284<li class="toctree-l2"><a class="reference internal" href="../general/helpers.html">Helpers</a></li>
285<li class="toctree-l2"><a class="reference internal" href="../general/libraries.html">Using CodeIgniter Libraries</a></li>
286<li class="toctree-l2"><a class="reference internal" href="../general/creating_libraries.html">Creating Libraries</a></li>
287<li class="toctree-l2"><a class="reference internal" href="../general/drivers.html">Using CodeIgniter Drivers</a></li>
288<li class="toctree-l2"><a class="reference internal" href="../general/creating_drivers.html">Creating Drivers</a></li>
289<li class="toctree-l2"><a class="reference internal" href="../general/core_classes.html">Creating Core System Classes</a></li>
290<li class="toctree-l2"><a class="reference internal" href="../general/ancillary_classes.html">Creating Ancillary Classes</a></li>
291<li class="toctree-l2"><a class="reference internal" href="../general/hooks.html">Hooks - Extending the Framework Core</a></li>
292<li class="toctree-l2"><a class="reference internal" href="../general/autoloader.html">Auto-loading Resources</a></li>
293<li class="toctree-l2"><a class="reference internal" href="../general/common_functions.html">Common Functions</a></li>
294<li class="toctree-l2"><a class="reference internal" href="../general/compatibility_functions.html">Compatibility Functions</a></li>
295<li class="toctree-l2"><a class="reference internal" href="../general/routing.html">URI Routing</a></li>
296<li class="toctree-l2"><a class="reference internal" href="../general/errors.html">Error Handling</a></li>
297<li class="toctree-l2"><a class="reference internal" href="../general/caching.html">Caching</a></li>
298<li class="toctree-l2"><a class="reference internal" href="../general/profiling.html">Profiling Your Application</a></li>
299<li class="toctree-l2"><a class="reference internal" href="../general/cli.html">Running via the CLI</a></li>
300<li class="toctree-l2"><a class="reference internal" href="../general/managing_apps.html">Managing your Applications</a></li>
301<li class="toctree-l2"><a class="reference internal" href="../general/environments.html">Handling Multiple Environments</a></li>
302<li class="toctree-l2"><a class="reference internal" href="../general/alternative_php.html">Alternate PHP Syntax for View Files</a></li>
303<li class="toctree-l2"><a class="reference internal" href="../general/security.html">Security</a></li>
304<li class="toctree-l2"><a class="reference internal" href="../general/styleguide.html">PHP Style Guide</a></li>
305</ul>
306</li>
307</ul>
308<ul>
309<li class="toctree-l1"><a class="reference internal" href="../libraries/index.html">Libraries</a><ul>
310<li class="toctree-l2"><a class="reference internal" href="../libraries/benchmark.html">Benchmarking Class</a></li>
311<li class="toctree-l2"><a class="reference internal" href="../libraries/caching.html">Caching Driver</a></li>
312<li class="toctree-l2"><a class="reference internal" href="../libraries/calendar.html">Calendaring Class</a></li>
313<li class="toctree-l2"><a class="reference internal" href="../libraries/cart.html">Shopping Cart Class</a></li>
314<li class="toctree-l2"><a class="reference internal" href="../libraries/config.html">Config Class</a></li>
315<li class="toctree-l2"><a class="reference internal" href="../libraries/email.html">Email Class</a></li>
316<li class="toctree-l2"><a class="reference internal" href="../libraries/encrypt.html">Encrypt Class</a></li>
317<li class="toctree-l2"><a class="reference internal" href="../libraries/encryption.html">Encryption Library</a></li>
318<li class="toctree-l2"><a class="reference internal" href="../libraries/file_uploading.html">File Uploading Class</a></li>
319<li class="toctree-l2"><a class="reference internal" href="../libraries/form_validation.html">Form Validation</a></li>
320<li class="toctree-l2"><a class="reference internal" href="../libraries/ftp.html">FTP Class</a></li>
321<li class="toctree-l2"><a class="reference internal" href="../libraries/image_lib.html">Image Manipulation Class</a></li>
322<li class="toctree-l2"><a class="reference internal" href="../libraries/input.html">Input Class</a></li>
323<li class="toctree-l2"><a class="reference internal" href="../libraries/javascript.html">Javascript Class</a></li>
324<li class="toctree-l2"><a class="reference internal" href="../libraries/language.html">Language Class</a></li>
325<li class="toctree-l2"><a class="reference internal" href="../libraries/loader.html">Loader Class</a></li>
326<li class="toctree-l2"><a class="reference internal" href="../libraries/migration.html">Migrations Class</a></li>
327<li class="toctree-l2"><a class="reference internal" href="../libraries/output.html">Output Class</a></li>
328<li class="toctree-l2"><a class="reference internal" href="../libraries/pagination.html">Pagination Class</a></li>
329<li class="toctree-l2"><a class="reference internal" href="../libraries/parser.html">Template Parser Class</a></li>
330<li class="toctree-l2"><a class="reference internal" href="../libraries/security.html">Security Class</a></li>
331<li class="toctree-l2"><a class="reference internal" href="../libraries/sessions.html">Session Library</a></li>
332<li class="toctree-l2"><a class="reference internal" href="../libraries/table.html">HTML Table Class</a></li>
333<li class="toctree-l2"><a class="reference internal" href="../libraries/trackback.html">Trackback Class</a></li>
334<li class="toctree-l2"><a class="reference internal" href="../libraries/typography.html">Typography Class</a></li>
335<li class="toctree-l2"><a class="reference internal" href="../libraries/unit_testing.html">Unit Testing Class</a></li>
336<li class="toctree-l2"><a class="reference internal" href="../libraries/uri.html">URI Class</a></li>
337<li class="toctree-l2"><a class="reference internal" href="../libraries/user_agent.html">User Agent Class</a></li>
338<li class="toctree-l2"><a class="reference internal" href="../libraries/xmlrpc.html">XML-RPC and XML-RPC Server Classes</a></li>
339<li class="toctree-l2"><a class="reference internal" href="../libraries/zip.html">Zip Encoding Class</a></li>
340</ul>
341</li>
342</ul>
343<ul class="current">
344<li class="toctree-l1 current"><a class="reference internal" href="index.html">Database Reference</a><ul class="current">
345<li class="toctree-l2"><a class="reference internal" href="examples.html">Quick Start: Usage Examples</a></li>
346<li class="toctree-l2"><a class="reference internal" href="configuration.html">Database Configuration</a></li>
347<li class="toctree-l2"><a class="reference internal" href="connecting.html">Connecting to a Database</a></li>
348<li class="toctree-l2"><a class="reference internal" href="queries.html">Running Queries</a></li>
349<li class="toctree-l2 current"><a class="current reference internal" href="#">Generating Query Results</a></li>
350<li class="toctree-l2"><a class="reference internal" href="helpers.html">Query Helper Functions</a></li>
351<li class="toctree-l2"><a class="reference internal" href="query_builder.html">Query Builder Class</a></li>
352<li class="toctree-l2"><a class="reference internal" href="transactions.html">Transactions</a></li>
353<li class="toctree-l2"><a class="reference internal" href="metadata.html">Getting MetaData</a></li>
354<li class="toctree-l2"><a class="reference internal" href="call_function.html">Custom Function Calls</a></li>
355<li class="toctree-l2"><a class="reference internal" href="caching.html">Query Caching</a></li>
356<li class="toctree-l2"><a class="reference internal" href="forge.html">Database Manipulation with Database Forge</a></li>
357<li class="toctree-l2"><a class="reference internal" href="utilities.html">Database Utilities Class</a></li>
358<li class="toctree-l2"><a class="reference internal" href="db_driver_reference.html">Database Driver Reference</a></li>
359</ul>
360</li>
361</ul>
362<ul>
363<li class="toctree-l1"><a class="reference internal" href="../helpers/index.html">Helpers</a><ul>
364<li class="toctree-l2"><a class="reference internal" href="../helpers/array_helper.html">Array Helper</a></li>
365<li class="toctree-l2"><a class="reference internal" href="../helpers/captcha_helper.html">CAPTCHA Helper</a></li>
366<li class="toctree-l2"><a class="reference internal" href="../helpers/cookie_helper.html">Cookie Helper</a></li>
367<li class="toctree-l2"><a class="reference internal" href="../helpers/date_helper.html">Date Helper</a></li>
368<li class="toctree-l2"><a class="reference internal" href="../helpers/directory_helper.html">Directory Helper</a></li>
369<li class="toctree-l2"><a class="reference internal" href="../helpers/download_helper.html">Download Helper</a></li>
370<li class="toctree-l2"><a class="reference internal" href="../helpers/email_helper.html">Email Helper</a></li>
371<li class="toctree-l2"><a class="reference internal" href="../helpers/file_helper.html">File Helper</a></li>
372<li class="toctree-l2"><a class="reference internal" href="../helpers/form_helper.html">Form Helper</a></li>
373<li class="toctree-l2"><a class="reference internal" href="../helpers/html_helper.html">HTML Helper</a></li>
374<li class="toctree-l2"><a class="reference internal" href="../helpers/inflector_helper.html">Inflector Helper</a></li>
375<li class="toctree-l2"><a class="reference internal" href="../helpers/language_helper.html">Language Helper</a></li>
376<li class="toctree-l2"><a class="reference internal" href="../helpers/number_helper.html">Number Helper</a></li>
377<li class="toctree-l2"><a class="reference internal" href="../helpers/path_helper.html">Path Helper</a></li>
378<li class="toctree-l2"><a class="reference internal" href="../helpers/security_helper.html">Security Helper</a></li>
379<li class="toctree-l2"><a class="reference internal" href="../helpers/smiley_helper.html">Smiley Helper</a></li>
380<li class="toctree-l2"><a class="reference internal" href="../helpers/string_helper.html">String Helper</a></li>
381<li class="toctree-l2"><a class="reference internal" href="../helpers/text_helper.html">Text Helper</a></li>
382<li class="toctree-l2"><a class="reference internal" href="../helpers/typography_helper.html">Typography Helper</a></li>
383<li class="toctree-l2"><a class="reference internal" href="../helpers/url_helper.html">URL Helper</a></li>
384<li class="toctree-l2"><a class="reference internal" href="../helpers/xml_helper.html">XML Helper</a></li>
385</ul>
386</li>
387</ul>
388
389
390
391 </div>
392 &nbsp;
393 </nav>
394
395 <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
396
397
398 <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
399 <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
400 <a href="../index.html">CodeIgniter</a>
401 </nav>
402
403
404
405 <div class="wy-nav-content">
406 <div class="rst-content">
407 <div role="navigation" aria-label="breadcrumbs navigation">
408 <ul class="wy-breadcrumbs">
409 <li><a href="../index.html">Docs</a> &raquo;</li>
410
411 <li><a href="index.html">Database Reference</a> &raquo;</li>
412
413 <li>Generating Query Results</li>
414 <li class="wy-breadcrumbs-aside">
415
416 </li>
417 <div style="float:right;margin-left:5px;" id="closeMe">
418 <img title="Classic Layout" alt="classic layout" src="data:image/gif;base64,R0lGODlhFAAUAJEAAAAAADMzM////wAAACH5BAUUAAIALAAAAAAUABQAAAImlI+py+0PU5gRBRDM3DxbWoXis42X13USOLauUIqnlsaH/eY6UwAAOw==" />
419 </div>
420 </ul>
421 <hr/>
422</div>
423 <div role="main" class="document">
424
425 <div class="section" id="generating-query-results">
426<h1>Generating Query Results<a class="headerlink" href="#generating-query-results" title="Permalink to this headline"></a></h1>
427<p>There are several ways to generate query results:</p>
428<div class="contents local topic" id="contents">
429<ul class="simple">
430<li><a class="reference internal" href="#result-arrays" id="id1">Result Arrays</a></li>
431<li><a class="reference internal" href="#result-rows" id="id2">Result Rows</a></li>
432<li><a class="reference internal" href="#custom-result-objects" id="id3">Custom Result Objects</a></li>
433<li><a class="reference internal" href="#result-helper-methods" id="id4">Result Helper Methods</a></li>
434<li><a class="reference internal" href="#class-reference" id="id5">Class Reference</a></li>
435</ul>
436</div>
437<div class="section" id="result-arrays">
438<h2><a class="toc-backref" href="#id1">Result Arrays</a><a class="headerlink" href="#result-arrays" title="Permalink to this headline"></a></h2>
439<p><strong>result()</strong></p>
440<p>This method returns the query result as an array of <strong>objects</strong>, or
441<strong>an empty array</strong> on failure. Typically you’ll use this in a foreach
442loop, like this:</p>
443<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$query</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">db</span><span class="o">-&gt;</span><span class="na">query</span><span class="p">(</span><span class="s2">&quot;YOUR QUERY&quot;</span><span class="p">);</span>
444
445<span class="k">foreach</span> <span class="p">(</span><span class="nv">$query</span><span class="o">-&gt;</span><span class="na">result</span><span class="p">()</span> <span class="k">as</span> <span class="nv">$row</span><span class="p">)</span>
446<span class="p">{</span>
447 <span class="k">echo</span> <span class="nv">$row</span><span class="o">-&gt;</span><span class="na">title</span><span class="p">;</span>
448 <span class="k">echo</span> <span class="nv">$row</span><span class="o">-&gt;</span><span class="na">name</span><span class="p">;</span>
449 <span class="k">echo</span> <span class="nv">$row</span><span class="o">-&gt;</span><span class="na">body</span><span class="p">;</span>
450<span class="p">}</span>
451</pre></div>
452</div>
453<p>The above method is an alias of <code class="docutils literal"><span class="pre">result_object()</span></code>.</p>
454<p>You can also pass a string to <code class="docutils literal"><span class="pre">result()</span></code> which represents a class to
455instantiate for each result object (note: this class must be loaded)</p>
456<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$query</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">db</span><span class="o">-&gt;</span><span class="na">query</span><span class="p">(</span><span class="s2">&quot;SELECT * FROM users;&quot;</span><span class="p">);</span>
457
458<span class="k">foreach</span> <span class="p">(</span><span class="nv">$query</span><span class="o">-&gt;</span><span class="na">result</span><span class="p">(</span><span class="s1">&#39;User&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="nv">$user</span><span class="p">)</span>
459<span class="p">{</span>
460 <span class="k">echo</span> <span class="nv">$user</span><span class="o">-&gt;</span><span class="na">name</span><span class="p">;</span> <span class="c1">// access attributes</span>
461 <span class="k">echo</span> <span class="nv">$user</span><span class="o">-&gt;</span><span class="na">reverse_name</span><span class="p">();</span> <span class="c1">// or methods defined on the &#39;User&#39; class</span>
462<span class="p">}</span>
463</pre></div>
464</div>
465<p><strong>result_array()</strong></p>
466<p>This method returns the query result as a pure array, or an empty
467array when no result is produced. Typically you’ll use this in a foreach
468loop, like this:</p>
469<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$query</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">db</span><span class="o">-&gt;</span><span class="na">query</span><span class="p">(</span><span class="s2">&quot;YOUR QUERY&quot;</span><span class="p">);</span>
470
471<span class="k">foreach</span> <span class="p">(</span><span class="nv">$query</span><span class="o">-&gt;</span><span class="na">result_array</span><span class="p">()</span> <span class="k">as</span> <span class="nv">$row</span><span class="p">)</span>
472<span class="p">{</span>
473 <span class="k">echo</span> <span class="nv">$row</span><span class="p">[</span><span class="s1">&#39;title&#39;</span><span class="p">];</span>
474 <span class="k">echo</span> <span class="nv">$row</span><span class="p">[</span><span class="s1">&#39;name&#39;</span><span class="p">];</span>
475 <span class="k">echo</span> <span class="nv">$row</span><span class="p">[</span><span class="s1">&#39;body&#39;</span><span class="p">];</span>
476<span class="p">}</span>
477</pre></div>
478</div>
479</div>
480<div class="section" id="result-rows">
481<h2><a class="toc-backref" href="#id2">Result Rows</a><a class="headerlink" href="#result-rows" title="Permalink to this headline"></a></h2>
482<p><strong>row()</strong></p>
483<p>This method returns a single result row. If your query has more than
484one row, it returns only the first row. The result is returned as an
485<strong>object</strong>. Here’s a usage example:</p>
486<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$query</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">db</span><span class="o">-&gt;</span><span class="na">query</span><span class="p">(</span><span class="s2">&quot;YOUR QUERY&quot;</span><span class="p">);</span>
487
488<span class="nv">$row</span> <span class="o">=</span> <span class="nv">$query</span><span class="o">-&gt;</span><span class="na">row</span><span class="p">();</span>
489
490<span class="k">if</span> <span class="p">(</span><span class="nb">isset</span><span class="p">(</span><span class="nv">$row</span><span class="p">))</span>
491<span class="p">{</span>
492 <span class="k">echo</span> <span class="nv">$row</span><span class="o">-&gt;</span><span class="na">title</span><span class="p">;</span>
493 <span class="k">echo</span> <span class="nv">$row</span><span class="o">-&gt;</span><span class="na">name</span><span class="p">;</span>
494 <span class="k">echo</span> <span class="nv">$row</span><span class="o">-&gt;</span><span class="na">body</span><span class="p">;</span>
495<span class="p">}</span>
496</pre></div>
497</div>
498<p>If you want a specific row returned you can submit the row number as a
499digit in the first parameter:</p>
500<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$row</span> <span class="o">=</span> <span class="nv">$query</span><span class="o">-&gt;</span><span class="na">row</span><span class="p">(</span><span class="mi">5</span><span class="p">);</span>
501</pre></div>
502</div>
503<p>You can also add a second String parameter, which is the name of a class
504to instantiate the row with:</p>
505<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$query</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">db</span><span class="o">-&gt;</span><span class="na">query</span><span class="p">(</span><span class="s2">&quot;SELECT * FROM users LIMIT 1;&quot;</span><span class="p">);</span>
506<span class="nv">$row</span> <span class="o">=</span> <span class="nv">$query</span><span class="o">-&gt;</span><span class="na">row</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="s1">&#39;User&#39;</span><span class="p">);</span>
507
508<span class="k">echo</span> <span class="nv">$row</span><span class="o">-&gt;</span><span class="na">name</span><span class="p">;</span> <span class="c1">// access attributes</span>
509<span class="k">echo</span> <span class="nv">$row</span><span class="o">-&gt;</span><span class="na">reverse_name</span><span class="p">();</span> <span class="c1">// or methods defined on the &#39;User&#39; class</span>
510</pre></div>
511</div>
512<p><strong>row_array()</strong></p>
513<p>Identical to the above <code class="docutils literal"><span class="pre">row()</span></code> method, except it returns an array.
514Example:</p>
515<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$query</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">db</span><span class="o">-&gt;</span><span class="na">query</span><span class="p">(</span><span class="s2">&quot;YOUR QUERY&quot;</span><span class="p">);</span>
516
517<span class="nv">$row</span> <span class="o">=</span> <span class="nv">$query</span><span class="o">-&gt;</span><span class="na">row_array</span><span class="p">();</span>
518
519<span class="k">if</span> <span class="p">(</span><span class="nb">isset</span><span class="p">(</span><span class="nv">$row</span><span class="p">))</span>
520<span class="p">{</span>
521 <span class="k">echo</span> <span class="nv">$row</span><span class="p">[</span><span class="s1">&#39;title&#39;</span><span class="p">];</span>
522 <span class="k">echo</span> <span class="nv">$row</span><span class="p">[</span><span class="s1">&#39;name&#39;</span><span class="p">];</span>
523 <span class="k">echo</span> <span class="nv">$row</span><span class="p">[</span><span class="s1">&#39;body&#39;</span><span class="p">];</span>
524<span class="p">}</span>
525</pre></div>
526</div>
527<p>If you want a specific row returned you can submit the row number as a
528digit in the first parameter:</p>
529<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$row</span> <span class="o">=</span> <span class="nv">$query</span><span class="o">-&gt;</span><span class="na">row_array</span><span class="p">(</span><span class="mi">5</span><span class="p">);</span>
530</pre></div>
531</div>
532<p>In addition, you can walk forward/backwards/first/last through your
533results using these variations:</p>
534<blockquote>
535<div><div class="line-block">
536<div class="line"><strong>$row = $query-&gt;first_row()</strong></div>
537<div class="line"><strong>$row = $query-&gt;last_row()</strong></div>
538<div class="line"><strong>$row = $query-&gt;next_row()</strong></div>
539<div class="line"><strong>$row = $query-&gt;previous_row()</strong></div>
540</div>
541</div></blockquote>
542<p>By default they return an object unless you put the word “array” in the
543parameter:</p>
544<blockquote>
545<div><div class="line-block">
546<div class="line"><strong>$row = $query-&gt;first_row(‘array’)</strong></div>
547<div class="line"><strong>$row = $query-&gt;last_row(‘array’)</strong></div>
548<div class="line"><strong>$row = $query-&gt;next_row(‘array’)</strong></div>
549<div class="line"><strong>$row = $query-&gt;previous_row(‘array’)</strong></div>
550</div>
551</div></blockquote>
552<div class="admonition note">
553<p class="first admonition-title">Note</p>
554<p class="last">All the methods above will load the whole result into memory
555(prefetching). Use <code class="docutils literal"><span class="pre">unbuffered_row()</span></code> for processing large
556result sets.</p>
557</div>
558<p><strong>unbuffered_row()</strong></p>
559<p>This method returns a single result row without prefetching the whole
560result in memory as <code class="docutils literal"><span class="pre">row()</span></code> does. If your query has more than one row,
561it returns the current row and moves the internal data pointer ahead.</p>
562<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$query</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">db</span><span class="o">-&gt;</span><span class="na">query</span><span class="p">(</span><span class="s2">&quot;YOUR QUERY&quot;</span><span class="p">);</span>
563
564<span class="k">while</span> <span class="p">(</span><span class="nv">$row</span> <span class="o">=</span> <span class="nv">$query</span><span class="o">-&gt;</span><span class="na">unbuffered_row</span><span class="p">())</span>
565<span class="p">{</span>
566 <span class="k">echo</span> <span class="nv">$row</span><span class="o">-&gt;</span><span class="na">title</span><span class="p">;</span>
567 <span class="k">echo</span> <span class="nv">$row</span><span class="o">-&gt;</span><span class="na">name</span><span class="p">;</span>
568 <span class="k">echo</span> <span class="nv">$row</span><span class="o">-&gt;</span><span class="na">body</span><span class="p">;</span>
569<span class="p">}</span>
570</pre></div>
571</div>
572<p>You can optionally pass ‘object’ (default) or ‘array’ in order to specify
573the returned value’s type:</p>
574<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$query</span><span class="o">-&gt;</span><span class="na">unbuffered_row</span><span class="p">();</span> <span class="c1">// object</span>
575<span class="nv">$query</span><span class="o">-&gt;</span><span class="na">unbuffered_row</span><span class="p">(</span><span class="s1">&#39;object&#39;</span><span class="p">);</span> <span class="c1">// object</span>
576<span class="nv">$query</span><span class="o">-&gt;</span><span class="na">unbuffered_row</span><span class="p">(</span><span class="s1">&#39;array&#39;</span><span class="p">);</span> <span class="c1">// associative array</span>
577</pre></div>
578</div>
579</div>
580<div class="section" id="custom-result-objects">
581<h2><a class="toc-backref" href="#id3">Custom Result Objects</a><a class="headerlink" href="#custom-result-objects" title="Permalink to this headline"></a></h2>
582<p>You can have the results returned as an instance of a custom class instead
583of a <code class="docutils literal"><span class="pre">stdClass</span></code> or array, as the <code class="docutils literal"><span class="pre">result()</span></code> and <code class="docutils literal"><span class="pre">result_array()</span></code>
584methods allow. This requires that the class is already loaded into memory.
585The object will have all values returned from the database set as properties.
586If these have been declared and are non-public then you should provide a
587<code class="docutils literal"><span class="pre">__set()</span></code> method to allow them to be set.</p>
588<p>Example:</p>
589<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">User</span> <span class="p">{</span>
590
591 <span class="k">public</span> <span class="nv">$id</span><span class="p">;</span>
592 <span class="k">public</span> <span class="nv">$email</span><span class="p">;</span>
593 <span class="k">public</span> <span class="nv">$username</span><span class="p">;</span>
594
595 <span class="k">protected</span> <span class="nv">$last_login</span><span class="p">;</span>
596
597 <span class="k">public</span> <span class="k">function</span> <span class="nf">last_login</span><span class="p">(</span><span class="nv">$format</span><span class="p">)</span>
598 <span class="p">{</span>
599 <span class="k">return</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">last_login</span><span class="o">-&gt;</span><span class="na">format</span><span class="p">(</span><span class="nv">$format</span><span class="p">);</span>
600 <span class="p">}</span>
601
602 <span class="k">public</span> <span class="k">function</span> <span class="nf">__set</span><span class="p">(</span><span class="nv">$name</span><span class="p">,</span> <span class="nv">$value</span><span class="p">)</span>
603 <span class="p">{</span>
604 <span class="k">if</span> <span class="p">(</span><span class="nv">$name</span> <span class="o">===</span> <span class="s1">&#39;last_login&#39;</span><span class="p">)</span>
605 <span class="p">{</span>
606 <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">last_login</span> <span class="o">=</span> <span class="nx">DateTime</span><span class="o">::</span><span class="na">createFromFormat</span><span class="p">(</span><span class="s1">&#39;U&#39;</span><span class="p">,</span> <span class="nv">$value</span><span class="p">);</span>
607 <span class="p">}</span>
608 <span class="p">}</span>
609
610 <span class="k">public</span> <span class="k">function</span> <span class="nf">__get</span><span class="p">(</span><span class="nv">$name</span><span class="p">)</span>
611 <span class="p">{</span>
612 <span class="k">if</span> <span class="p">(</span><span class="nb">isset</span><span class="p">(</span><span class="nv">$this</span><span class="o">-&gt;</span><span class="nv">$name</span><span class="p">))</span>
613 <span class="p">{</span>
614 <span class="k">return</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="nv">$name</span><span class="p">;</span>
615 <span class="p">}</span>
616 <span class="p">}</span>
617<span class="p">}</span>
618</pre></div>
619</div>
620<p>In addition to the two methods listed below, the following methods also can
621take a class name to return the results as: <code class="docutils literal"><span class="pre">first_row()</span></code>, <code class="docutils literal"><span class="pre">last_row()</span></code>,
622<code class="docutils literal"><span class="pre">next_row()</span></code>, and <code class="docutils literal"><span class="pre">previous_row()</span></code>.</p>
623<p><strong>custom_result_object()</strong></p>
624<p>Returns the entire result set as an array of instances of the class requested.
625The only parameter is the name of the class to instantiate.</p>
626<p>Example:</p>
627<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$query</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">db</span><span class="o">-&gt;</span><span class="na">query</span><span class="p">(</span><span class="s2">&quot;YOUR QUERY&quot;</span><span class="p">);</span>
628
629<span class="nv">$rows</span> <span class="o">=</span> <span class="nv">$query</span><span class="o">-&gt;</span><span class="na">custom_result_object</span><span class="p">(</span><span class="s1">&#39;User&#39;</span><span class="p">);</span>
630
631<span class="k">foreach</span> <span class="p">(</span><span class="nv">$rows</span> <span class="k">as</span> <span class="nv">$row</span><span class="p">)</span>
632<span class="p">{</span>
633 <span class="k">echo</span> <span class="nv">$row</span><span class="o">-&gt;</span><span class="na">id</span><span class="p">;</span>
634 <span class="k">echo</span> <span class="nv">$row</span><span class="o">-&gt;</span><span class="na">email</span><span class="p">;</span>
635 <span class="k">echo</span> <span class="nv">$row</span><span class="o">-&gt;</span><span class="na">last_login</span><span class="p">(</span><span class="s1">&#39;Y-m-d&#39;</span><span class="p">);</span>
636<span class="p">}</span>
637</pre></div>
638</div>
639<p><strong>custom_row_object()</strong></p>
640<p>Returns a single row from your query results. The first parameter is the row
641number of the results. The second parameter is the class name to instantiate.</p>
642<p>Example:</p>
643<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$query</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">db</span><span class="o">-&gt;</span><span class="na">query</span><span class="p">(</span><span class="s2">&quot;YOUR QUERY&quot;</span><span class="p">);</span>
644
645<span class="nv">$row</span> <span class="o">=</span> <span class="nv">$query</span><span class="o">-&gt;</span><span class="na">custom_row_object</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="s1">&#39;User&#39;</span><span class="p">);</span>
646
647<span class="k">if</span> <span class="p">(</span><span class="nb">isset</span><span class="p">(</span><span class="nv">$row</span><span class="p">))</span>
648<span class="p">{</span>
649 <span class="k">echo</span> <span class="nv">$row</span><span class="o">-&gt;</span><span class="na">email</span><span class="p">;</span> <span class="c1">// access attributes</span>
650 <span class="k">echo</span> <span class="nv">$row</span><span class="o">-&gt;</span><span class="na">last_login</span><span class="p">(</span><span class="s1">&#39;Y-m-d&#39;</span><span class="p">);</span> <span class="c1">// access class methods</span>
651<span class="p">}</span>
652</pre></div>
653</div>
654<p>You can also use the <code class="docutils literal"><span class="pre">row()</span></code> method in exactly the same way.</p>
655<p>Example:</p>
656<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$row</span> <span class="o">=</span> <span class="nv">$query</span><span class="o">-&gt;</span><span class="na">custom_row_object</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="s1">&#39;User&#39;</span><span class="p">);</span>
657</pre></div>
658</div>
659</div>
660<div class="section" id="result-helper-methods">
661<h2><a class="toc-backref" href="#id4">Result Helper Methods</a><a class="headerlink" href="#result-helper-methods" title="Permalink to this headline"></a></h2>
662<p><strong>num_rows()</strong></p>
663<p>The number of rows returned by the query. Note: In this example, $query
664is the variable that the query result object is assigned to:</p>
665<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$query</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">db</span><span class="o">-&gt;</span><span class="na">query</span><span class="p">(</span><span class="s1">&#39;SELECT * FROM my_table&#39;</span><span class="p">);</span>
666
667<span class="k">echo</span> <span class="nv">$query</span><span class="o">-&gt;</span><span class="na">num_rows</span><span class="p">();</span>
668</pre></div>
669</div>
670<div class="admonition note">
671<p class="first admonition-title">Note</p>
672<p class="last">Not all database drivers have a native way of getting the total
673number of rows for a result set. When this is the case, all of
674the data is prefetched and <code class="docutils literal"><span class="pre">count()</span></code> is manually called on the
675resulting array in order to achieve the same result.</p>
676</div>
677<p><strong>num_fields()</strong></p>
678<p>The number of FIELDS (columns) returned by the query. Make sure to call
679the method using your query result object:</p>
680<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$query</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">db</span><span class="o">-&gt;</span><span class="na">query</span><span class="p">(</span><span class="s1">&#39;SELECT * FROM my_table&#39;</span><span class="p">);</span>
681
682<span class="k">echo</span> <span class="nv">$query</span><span class="o">-&gt;</span><span class="na">num_fields</span><span class="p">();</span>
683</pre></div>
684</div>
685<p><strong>free_result()</strong></p>
686<p>It frees the memory associated with the result and deletes the result
687resource ID. Normally PHP frees its memory automatically at the end of
688script execution. However, if you are running a lot of queries in a
689particular script you might want to free the result after each query
690result has been generated in order to cut down on memory consumption.</p>
691<p>Example:</p>
692<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$query</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">db</span><span class="o">-&gt;</span><span class="na">query</span><span class="p">(</span><span class="s1">&#39;SELECT title FROM my_table&#39;</span><span class="p">);</span>
693
694<span class="k">foreach</span> <span class="p">(</span><span class="nv">$query</span><span class="o">-&gt;</span><span class="na">result</span><span class="p">()</span> <span class="k">as</span> <span class="nv">$row</span><span class="p">)</span>
695<span class="p">{</span>
696 <span class="k">echo</span> <span class="nv">$row</span><span class="o">-&gt;</span><span class="na">title</span><span class="p">;</span>
697<span class="p">}</span>
698
699<span class="nv">$query</span><span class="o">-&gt;</span><span class="na">free_result</span><span class="p">();</span> <span class="c1">// The $query result object will no longer be available</span>
700
701<span class="nv">$query2</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">db</span><span class="o">-&gt;</span><span class="na">query</span><span class="p">(</span><span class="s1">&#39;SELECT name FROM some_table&#39;</span><span class="p">);</span>
702
703<span class="nv">$row</span> <span class="o">=</span> <span class="nv">$query2</span><span class="o">-&gt;</span><span class="na">row</span><span class="p">();</span>
704<span class="k">echo</span> <span class="nv">$row</span><span class="o">-&gt;</span><span class="na">name</span><span class="p">;</span>
705<span class="nv">$query2</span><span class="o">-&gt;</span><span class="na">free_result</span><span class="p">();</span> <span class="c1">// The $query2 result object will no longer be available</span>
706</pre></div>
707</div>
708<p><strong>data_seek()</strong></p>
709<p>This method sets the internal pointer for the next result row to be
710fetched. It is only useful in combination with <code class="docutils literal"><span class="pre">unbuffered_row()</span></code>.</p>
711<p>It accepts a positive integer value, which defaults to 0 and returns
712TRUE on success or FALSE on failure.</p>
713<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$query</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">db</span><span class="o">-&gt;</span><span class="na">query</span><span class="p">(</span><span class="s1">&#39;SELECT `field_name` FROM `table_name`&#39;</span><span class="p">);</span>
714<span class="nv">$query</span><span class="o">-&gt;</span><span class="na">data_seek</span><span class="p">(</span><span class="mi">5</span><span class="p">);</span> <span class="c1">// Skip the first 5 rows</span>
715<span class="nv">$row</span> <span class="o">=</span> <span class="nv">$query</span><span class="o">-&gt;</span><span class="na">unbuffered_row</span><span class="p">();</span>
716</pre></div>
717</div>
718<div class="admonition note">
719<p class="first admonition-title">Note</p>
720<p class="last">Not all database drivers support this feature and will return FALSE.
721Most notably - you won’t be able to use it with PDO.</p>
722</div>
723</div>
724<div class="section" id="class-reference">
725<h2><a class="toc-backref" href="#id5">Class Reference</a><a class="headerlink" href="#class-reference" title="Permalink to this headline"></a></h2>
726<dl class="class">
727<dt id="CI_DB_result">
728<em class="property">class </em><code class="descname">CI_DB_result</code><a class="headerlink" href="#CI_DB_result" title="Permalink to this definition"></a></dt>
729<dd><dl class="method">
730<dt id="CI_DB_result::result">
731<code class="descname">result</code><span class="sig-paren">(</span><span class="optional">[</span><em>$type = 'object'</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_result::result" title="Permalink to this definition"></a></dt>
732<dd><table class="docutils field-list" frame="void" rules="none">
733<col class="field-name" />
734<col class="field-body" />
735<tbody valign="top">
736<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
737<li><strong>$type</strong> (<em>string</em>) – Type of requested results - array, object, or class name</li>
738</ul>
739</td>
740</tr>
741<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Array containing the fetched rows</p>
742</td>
743</tr>
744<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">array</p>
745</td>
746</tr>
747</tbody>
748</table>
749<p>A wrapper for the <code class="docutils literal"><span class="pre">result_array()</span></code>, <code class="docutils literal"><span class="pre">result_object()</span></code>
750and <code class="docutils literal"><span class="pre">custom_result_object()</span></code> methods.</p>
751<p>Usage: see <a class="reference internal" href="#result-arrays">Result Arrays</a>.</p>
752</dd></dl>
753
754<dl class="method">
755<dt id="CI_DB_result::result_array">
756<code class="descname">result_array</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_result::result_array" title="Permalink to this definition"></a></dt>
757<dd><table class="docutils field-list" frame="void" rules="none">
758<col class="field-name" />
759<col class="field-body" />
760<tbody valign="top">
761<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">Array containing the fetched rows</td>
762</tr>
763<tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">array</td>
764</tr>
765</tbody>
766</table>
767<p>Returns the query results as an array of rows, where each
768row is itself an associative array.</p>
769<p>Usage: see <a class="reference internal" href="#result-arrays">Result Arrays</a>.</p>
770</dd></dl>
771
772<dl class="method">
773<dt id="CI_DB_result::result_object">
774<code class="descname">result_object</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_result::result_object" title="Permalink to this definition"></a></dt>
775<dd><table class="docutils field-list" frame="void" rules="none">
776<col class="field-name" />
777<col class="field-body" />
778<tbody valign="top">
779<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">Array containing the fetched rows</td>
780</tr>
781<tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">array</td>
782</tr>
783</tbody>
784</table>
785<p>Returns the query results as an array of rows, where each
786row is an object of type <code class="docutils literal"><span class="pre">stdClass</span></code>.</p>
787<p>Usage: see <a class="reference internal" href="#result-arrays">Result Arrays</a>.</p>
788</dd></dl>
789
790<dl class="method">
791<dt id="CI_DB_result::custom_result_object">
792<code class="descname">custom_result_object</code><span class="sig-paren">(</span><em>$class_name</em><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_result::custom_result_object" title="Permalink to this definition"></a></dt>
793<dd><table class="docutils field-list" frame="void" rules="none">
794<col class="field-name" />
795<col class="field-body" />
796<tbody valign="top">
797<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
798<li><strong>$class_name</strong> (<em>string</em>) – Class name for the resulting rows</li>
799</ul>
800</td>
801</tr>
802<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Array containing the fetched rows</p>
803</td>
804</tr>
805<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">array</p>
806</td>
807</tr>
808</tbody>
809</table>
810<p>Returns the query results as an array of rows, where each
811row is an instance of the specified class.</p>
812</dd></dl>
813
814<dl class="method">
815<dt id="CI_DB_result::row">
816<code class="descname">row</code><span class="sig-paren">(</span><span class="optional">[</span><em>$n = 0</em><span class="optional">[</span>, <em>$type = 'object'</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_result::row" title="Permalink to this definition"></a></dt>
817<dd><table class="docutils field-list" frame="void" rules="none">
818<col class="field-name" />
819<col class="field-body" />
820<tbody valign="top">
821<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
822<li><strong>$n</strong> (<em>int</em>) – Index of the query results row to be returned</li>
823<li><strong>$type</strong> (<em>string</em>) – Type of the requested result - array, object, or class name</li>
824</ul>
825</td>
826</tr>
827<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The requested row or NULL if it doesn’t exist</p>
828</td>
829</tr>
830<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">mixed</p>
831</td>
832</tr>
833</tbody>
834</table>
835<p>A wrapper for the <code class="docutils literal"><span class="pre">row_array()</span></code>, <code class="docutils literal"><span class="pre">row_object()</span> <span class="pre">and</span>
836<span class="pre">``custom_row_object()</span></code> methods.</p>
837<p>Usage: see <a class="reference internal" href="#result-rows">Result Rows</a>.</p>
838</dd></dl>
839
840<dl class="method">
841<dt id="CI_DB_result::unbuffered_row">
842<code class="descname">unbuffered_row</code><span class="sig-paren">(</span><span class="optional">[</span><em>$type = 'object'</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_result::unbuffered_row" title="Permalink to this definition"></a></dt>
843<dd><table class="docutils field-list" frame="void" rules="none">
844<col class="field-name" />
845<col class="field-body" />
846<tbody valign="top">
847<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
848<li><strong>$type</strong> (<em>string</em>) – Type of the requested result - array, object, or class name</li>
849</ul>
850</td>
851</tr>
852<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Next row from the result set or NULL if it doesn’t exist</p>
853</td>
854</tr>
855<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">mixed</p>
856</td>
857</tr>
858</tbody>
859</table>
860<p>Fetches the next result row and returns it in the
861requested form.</p>
862<p>Usage: see <a class="reference internal" href="#result-rows">Result Rows</a>.</p>
863</dd></dl>
864
865<dl class="method">
866<dt id="CI_DB_result::row_array">
867<code class="descname">row_array</code><span class="sig-paren">(</span><span class="optional">[</span><em>$n = 0</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_result::row_array" title="Permalink to this definition"></a></dt>
868<dd><table class="docutils field-list" frame="void" rules="none">
869<col class="field-name" />
870<col class="field-body" />
871<tbody valign="top">
872<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
873<li><strong>$n</strong> (<em>int</em>) – Index of the query results row to be returned</li>
874</ul>
875</td>
876</tr>
877<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The requested row or NULL if it doesn’t exist</p>
878</td>
879</tr>
880<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">array</p>
881</td>
882</tr>
883</tbody>
884</table>
885<p>Returns the requested result row as an associative array.</p>
886<p>Usage: see <a class="reference internal" href="#result-rows">Result Rows</a>.</p>
887</dd></dl>
888
889<dl class="method">
890<dt id="CI_DB_result::row_object">
891<code class="descname">row_object</code><span class="sig-paren">(</span><span class="optional">[</span><em>$n = 0</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_result::row_object" title="Permalink to this definition"></a></dt>
892<dd><table class="docutils field-list" frame="void" rules="none">
893<col class="field-name" />
894<col class="field-body" />
895<tbody valign="top">
896<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
897<li><strong>$n</strong> (<em>int</em>) – Index of the query results row to be returned</li>
898</ul>
899</td>
900</tr>
901<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The requested row or NULL if it doesn’t exist</p>
902</td>
903</tr>
904<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">stdClass</p>
905</td>
906</tr>
907</tbody>
908</table>
909<p>Returns the requested result row as an object of type
910<code class="docutils literal"><span class="pre">stdClass</span></code>.</p>
911<p>Usage: see <a class="reference internal" href="#result-rows">Result Rows</a>.</p>
912</dd></dl>
913
914<dl class="method">
915<dt id="CI_DB_result::custom_row_object">
916<code class="descname">custom_row_object</code><span class="sig-paren">(</span><em>$n</em>, <em>$type</em><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_result::custom_row_object" title="Permalink to this definition"></a></dt>
917<dd><table class="docutils field-list" frame="void" rules="none">
918<col class="field-name" />
919<col class="field-body" />
920<tbody valign="top">
921<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
922<li><strong>$n</strong> (<em>int</em>) – Index of the results row to return</li>
923<li><strong>$class_name</strong> (<em>string</em>) – Class name for the resulting row</li>
924</ul>
925</td>
926</tr>
927<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The requested row or NULL if it doesn’t exist</p>
928</td>
929</tr>
930<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">$type</p>
931</td>
932</tr>
933</tbody>
934</table>
935<p>Returns the requested result row as an instance of the
936requested class.</p>
937</dd></dl>
938
939<dl class="method">
940<dt id="CI_DB_result::data_seek">
941<code class="descname">data_seek</code><span class="sig-paren">(</span><span class="optional">[</span><em>$n = 0</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_result::data_seek" title="Permalink to this definition"></a></dt>
942<dd><table class="docutils field-list" frame="void" rules="none">
943<col class="field-name" />
944<col class="field-body" />
945<tbody valign="top">
946<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
947<li><strong>$n</strong> (<em>int</em>) – Index of the results row to be returned next</li>
948</ul>
949</td>
950</tr>
951<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">TRUE on success, FALSE on failure</p>
952</td>
953</tr>
954<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">bool</p>
955</td>
956</tr>
957</tbody>
958</table>
959<p>Moves the internal results row pointer to the desired offset.</p>
960<p>Usage: see <a class="reference internal" href="#result-helper-methods">Result Helper Methods</a>.</p>
961</dd></dl>
962
963<dl class="method">
964<dt id="CI_DB_result::set_row">
965<code class="descname">set_row</code><span class="sig-paren">(</span><em>$key</em><span class="optional">[</span>, <em>$value = NULL</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_result::set_row" title="Permalink to this definition"></a></dt>
966<dd><table class="docutils field-list" frame="void" rules="none">
967<col class="field-name" />
968<col class="field-body" />
969<tbody valign="top">
970<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
971<li><strong>$key</strong> (<em>mixed</em>) – Column name or array of key/value pairs</li>
972<li><strong>$value</strong> (<em>mixed</em>) – Value to assign to the column, $key is a single field name</li>
973</ul>
974</td>
975</tr>
976<tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">void</p>
977</td>
978</tr>
979</tbody>
980</table>
981<p>Assigns a value to a particular column.</p>
982</dd></dl>
983
984<dl class="method">
985<dt id="CI_DB_result::next_row">
986<code class="descname">next_row</code><span class="sig-paren">(</span><span class="optional">[</span><em>$type = 'object'</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_result::next_row" title="Permalink to this definition"></a></dt>
987<dd><table class="docutils field-list" frame="void" rules="none">
988<col class="field-name" />
989<col class="field-body" />
990<tbody valign="top">
991<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
992<li><strong>$type</strong> (<em>string</em>) – Type of the requested result - array, object, or class name</li>
993</ul>
994</td>
995</tr>
996<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Next row of result set, or NULL if it doesn’t exist</p>
997</td>
998</tr>
999<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">mixed</p>
1000</td>
1001</tr>
1002</tbody>
1003</table>
1004<p>Returns the next row from the result set.</p>
1005</dd></dl>
1006
1007<dl class="method">
1008<dt id="CI_DB_result::previous_row">
1009<code class="descname">previous_row</code><span class="sig-paren">(</span><span class="optional">[</span><em>$type = 'object'</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_result::previous_row" title="Permalink to this definition"></a></dt>
1010<dd><table class="docutils field-list" frame="void" rules="none">
1011<col class="field-name" />
1012<col class="field-body" />
1013<tbody valign="top">
1014<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
1015<li><strong>$type</strong> (<em>string</em>) – Type of the requested result - array, object, or class name</li>
1016</ul>
1017</td>
1018</tr>
1019<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Previous row of result set, or NULL if it doesn’t exist</p>
1020</td>
1021</tr>
1022<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">mixed</p>
1023</td>
1024</tr>
1025</tbody>
1026</table>
1027<p>Returns the previous row from the result set.</p>
1028</dd></dl>
1029
1030<dl class="method">
1031<dt id="CI_DB_result::first_row">
1032<code class="descname">first_row</code><span class="sig-paren">(</span><span class="optional">[</span><em>$type = 'object'</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_result::first_row" title="Permalink to this definition"></a></dt>
1033<dd><table class="docutils field-list" frame="void" rules="none">
1034<col class="field-name" />
1035<col class="field-body" />
1036<tbody valign="top">
1037<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
1038<li><strong>$type</strong> (<em>string</em>) – Type of the requested result - array, object, or class name</li>
1039</ul>
1040</td>
1041</tr>
1042<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">First row of result set, or NULL if it doesn’t exist</p>
1043</td>
1044</tr>
1045<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">mixed</p>
1046</td>
1047</tr>
1048</tbody>
1049</table>
1050<p>Returns the first row from the result set.</p>
1051</dd></dl>
1052
1053<dl class="method">
1054<dt id="CI_DB_result::last_row">
1055<code class="descname">last_row</code><span class="sig-paren">(</span><span class="optional">[</span><em>$type = 'object'</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_result::last_row" title="Permalink to this definition"></a></dt>
1056<dd><table class="docutils field-list" frame="void" rules="none">
1057<col class="field-name" />
1058<col class="field-body" />
1059<tbody valign="top">
1060<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
1061<li><strong>$type</strong> (<em>string</em>) – Type of the requested result - array, object, or class name</li>
1062</ul>
1063</td>
1064</tr>
1065<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Last row of result set, or NULL if it doesn’t exist</p>
1066</td>
1067</tr>
1068<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">mixed</p>
1069</td>
1070</tr>
1071</tbody>
1072</table>
1073<p>Returns the last row from the result set.</p>
1074</dd></dl>
1075
1076<dl class="method">
1077<dt id="CI_DB_result::num_rows">
1078<code class="descname">num_rows</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_result::num_rows" title="Permalink to this definition"></a></dt>
1079<dd><table class="docutils field-list" frame="void" rules="none">
1080<col class="field-name" />
1081<col class="field-body" />
1082<tbody valign="top">
1083<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">Number of rows in the result set</td>
1084</tr>
1085<tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">int</td>
1086</tr>
1087</tbody>
1088</table>
1089<p>Returns the number of rows in the result set.</p>
1090<p>Usage: see <a class="reference internal" href="#result-helper-methods">Result Helper Methods</a>.</p>
1091</dd></dl>
1092
1093<dl class="method">
1094<dt id="CI_DB_result::num_fields">
1095<code class="descname">num_fields</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_result::num_fields" title="Permalink to this definition"></a></dt>
1096<dd><table class="docutils field-list" frame="void" rules="none">
1097<col class="field-name" />
1098<col class="field-body" />
1099<tbody valign="top">
1100<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">Number of fields in the result set</td>
1101</tr>
1102<tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">int</td>
1103</tr>
1104</tbody>
1105</table>
1106<p>Returns the number of fields in the result set.</p>
1107<p>Usage: see <a class="reference internal" href="#result-helper-methods">Result Helper Methods</a>.</p>
1108</dd></dl>
1109
1110<dl class="method">
1111<dt id="CI_DB_result::field_data">
1112<code class="descname">field_data</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_result::field_data" title="Permalink to this definition"></a></dt>
1113<dd><table class="docutils field-list" frame="void" rules="none">
1114<col class="field-name" />
1115<col class="field-body" />
1116<tbody valign="top">
1117<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">Array containing field meta-data</td>
1118</tr>
1119<tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">array</td>
1120</tr>
1121</tbody>
1122</table>
1123<p>Generates an array of <code class="docutils literal"><span class="pre">stdClass</span></code> objects containing
1124field meta-data.</p>
1125</dd></dl>
1126
1127<dl class="method">
1128<dt id="CI_DB_result::free_result">
1129<code class="descname">free_result</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_result::free_result" title="Permalink to this definition"></a></dt>
1130<dd><table class="docutils field-list" frame="void" rules="none">
1131<col class="field-name" />
1132<col class="field-body" />
1133<tbody valign="top">
1134<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">void</td>
1135</tr>
1136</tbody>
1137</table>
1138<p>Frees a result set.</p>
1139<p>Usage: see <a class="reference internal" href="#result-helper-methods">Result Helper Methods</a>.</p>
1140</dd></dl>
1141
1142<dl class="method">
1143<dt id="CI_DB_result::list_fields">
1144<code class="descname">list_fields</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_result::list_fields" title="Permalink to this definition"></a></dt>
1145<dd><table class="docutils field-list" frame="void" rules="none">
1146<col class="field-name" />
1147<col class="field-body" />
1148<tbody valign="top">
1149<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">Array of column names</td>
1150</tr>
1151<tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">array</td>
1152</tr>
1153</tbody>
1154</table>
1155<p>Returns an array containing the field names in the
1156result set.</p>
1157</dd></dl>
1158
1159</dd></dl>
1160
1161</div>
1162</div>
1163
1164
1165 </div>
1166 <footer>
1167
1168 <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
1169
1170 <a href="helpers.html" class="btn btn-neutral float-right" title="Query Helper Methods">Next <span class="fa fa-arrow-circle-right"></span></a>
1171
1172
1173 <a href="queries.html" class="btn btn-neutral" title="Queries"><span class="fa fa-arrow-circle-left"></span> Previous</a>
1174
1175 </div>
1176
1177
1178 <hr/>
1179
1180 <div role="contentinfo">
1181 <p>
1182 &copy; Copyright 2014 - 2019, British Columbia Institute of Technology.
1183 Last updated on Jan 16, 2019.
1184 </p>
1185 </div>
1186
1187 Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
1188
1189</footer>
1190 </div>
1191 </div>
1192
1193 </section>
1194
1195 </div>
1196
1197
1198
1199
1200
1201 <script type="text/javascript">
1202 var DOCUMENTATION_OPTIONS = {
1203 URL_ROOT:'../',
1204 VERSION:'3.1.10',
1205 COLLAPSE_INDEX:false,
1206 FILE_SUFFIX:'.html',
1207 HAS_SOURCE: false
1208 };
1209 </script>
1210 <script type="text/javascript" src="../_static/jquery.js"></script>
1211 <script type="text/javascript" src="../_static/underscore.js"></script>
1212 <script type="text/javascript" src="../_static/doctools.js"></script>
1213
1214
1215
1216
1217
1218 <script type="text/javascript" src="../_static/js/theme.js"></script>
1219
1220
1221
1222
1223 <script type="text/javascript">
1224 jQuery(function () {
1225 SphinxRtdTheme.StickyNav.enable();
1226 });
1227 </script>
1228
1229
1230</body>
1231</html>