Skip to content
This repository
Browse code

replacing the old HTML user guide with a Sphinx-managed user guide

  • Loading branch information...
commit 8ede1a2ecbb62577afd32996956c5feaf7ddf9b6 1 parent d1ecd5c
Derek Jones authored October 05, 2011

Showing 131 changed files with 6 additions and 25,124 deletions. Show diff stats Hide diff stats

  1. 7  .gitignore
  2. 1,451  user_guide/changelog.html
  3. 821  user_guide/database/active_record.html
  4. 220  user_guide/database/caching.html
  5. 118  user_guide/database/call_function.html
  6. 164  user_guide/database/configuration.html
  7. 190  user_guide/database/connecting.html
  8. 217  user_guide/database/examples.html
  9. 163  user_guide/database/fields.html
  10. 238  user_guide/database/forge.html
  11. 151  user_guide/database/helpers.html
  12. 99  user_guide/database/index.html
  13. 158  user_guide/database/queries.html
  14. 259  user_guide/database/results.html
  15. 113  user_guide/database/table_data.html
  16. 200  user_guide/database/transactions.html
  17. 315  user_guide/database/utilities.html
  18. 87  user_guide/doc_style/index.html
  19. 128  user_guide/doc_style/template.html
  20. 147  user_guide/general/alternative_php.html
  21. 117  user_guide/general/ancillary_classes.html
  22. 100  user_guide/general/autoloader.html
  23. 115  user_guide/general/caching.html
  24. 150  user_guide/general/cli.html
  25. 127  user_guide/general/common_functions.html
  26. 388  user_guide/general/controllers.html
  27. 186  user_guide/general/core_classes.html
  28. 100  user_guide/general/creating_drivers.html
  29. 293  user_guide/general/creating_libraries.html
  30. 87  user_guide/general/credits.html
  31. 104  user_guide/general/drivers.html
  32. 126  user_guide/general/environments.html
  33. 140  user_guide/general/errors.html
  34. 185  user_guide/general/helpers.html
  35. 165  user_guide/general/hooks.html
  36. 98  user_guide/general/libraries.html
  37. 133  user_guide/general/managing_apps.html
  38. 251  user_guide/general/models.html
  39. 186  user_guide/general/profiling.html
  40. 77  user_guide/general/quick_reference.html
  41. 82  user_guide/general/requirements.html
  42. 128  user_guide/general/reserved_names.html
  43. 171  user_guide/general/routing.html
  44. 164  user_guide/general/security.html
  45. 679  user_guide/general/styleguide.html
  46. 151  user_guide/general/urls.html
  47. 274  user_guide/general/views.html
  48. 170  user_guide/helpers/array_helper.html
  49. 195  user_guide/helpers/captcha_helper.html
  50. 107  user_guide/helpers/cookie_helper.html
  51. 422  user_guide/helpers/date_helper.html
  52. 143  user_guide/helpers/directory_helper.html
  53. 112  user_guide/helpers/download_helper.html
  54. 102  user_guide/helpers/email_helper.html
  55. 179  user_guide/helpers/file_helper.html
  56. 484  user_guide/helpers/form_helper.html
  57. 395  user_guide/helpers/html_helper.html
  58. 151  user_guide/helpers/inflector_helper.html
  59. 98  user_guide/helpers/language_helper.html
  60. 113  user_guide/helpers/number_helper.html
  61. 106  user_guide/helpers/path_helper.html
  62. 132  user_guide/helpers/security_helper.html
  63. 215  user_guide/helpers/smiley_helper.html
  64. 189  user_guide/helpers/string_helper.html
  65. 211  user_guide/helpers/text_helper.html
  66. 112  user_guide/helpers/typography_helper.html
  67. 302  user_guide/helpers/url_helper.html
  68. 105  user_guide/helpers/xml_helper.html
  69. BIN  user_guide/images/appflowchart.gif
  70. BIN  user_guide/images/codeigniter_1.7.1_helper_reference.pdf
  71. BIN  user_guide/images/codeigniter_1.7.1_library_reference.png
  72. BIN  user_guide/images/nav_bg_darker.jpg
  73. BIN  user_guide/images/nav_separator_darker.jpg
  74. BIN  user_guide/images/nav_toggle_darker.jpg
  75. BIN  user_guide/images/reactor-bullet.png
  76. BIN  user_guide/images/transparent.gif
  77. 99  user_guide/index.html
  78. 115  user_guide/installation/downloads.html
  79. 110  user_guide/installation/index.html
  80. 90  user_guide/installation/troubleshooting.html
  81. 92  user_guide/installation/upgrade_120.html
  82. 203  user_guide/installation/upgrade_130.html
  83. 102  user_guide/installation/upgrade_131.html
  84. 100  user_guide/installation/upgrade_132.html
  85. 112  user_guide/installation/upgrade_133.html
  86. 145  user_guide/installation/upgrade_140.html
  87. 148  user_guide/installation/upgrade_141.html
  88. 178  user_guide/installation/upgrade_150.html
  89. 111  user_guide/installation/upgrade_152.html
  90. 100  user_guide/installation/upgrade_153.html
  91. 116  user_guide/installation/upgrade_154.html
  92. 125  user_guide/installation/upgrade_160.html
  93. 98  user_guide/installation/upgrade_161.html
  94. 106  user_guide/installation/upgrade_162.html
  95. 99  user_guide/installation/upgrade_163.html
  96. 121  user_guide/installation/upgrade_170.html
  97. 98  user_guide/installation/upgrade_171.html
  98. 109  user_guide/installation/upgrade_172.html
  99. 131  user_guide/installation/upgrade_200.html
  100. 105  user_guide/installation/upgrade_201.html
  101. 97  user_guide/installation/upgrade_202.html
  102. 121  user_guide/installation/upgrade_203.html
  103. 91  user_guide/installation/upgrade_210.html
  104. 144  user_guide/installation/upgrade_b11.html
  105. 106  user_guide/installation/upgrading.html
  106. 198  user_guide/libraries/benchmark.html
  107. 193  user_guide/libraries/caching.html
  108. 249  user_guide/libraries/calendar.html
  109. 346  user_guide/libraries/cart.html
  110. 222  user_guide/libraries/config.html
  111. 310  user_guide/libraries/email.html
  112. 224  user_guide/libraries/encryption.html
  113. 458  user_guide/libraries/file_uploading.html
  114. 1,257  user_guide/libraries/form_validation.html
  115. 316  user_guide/libraries/ftp.html
  116. 667  user_guide/libraries/image_lib.html
  117. 295  user_guide/libraries/input.html
  118. 247  user_guide/libraries/javascript.html
  119. 137  user_guide/libraries/language.html
  120. 273  user_guide/libraries/loader.html
  121. 177  user_guide/libraries/output.html
  122. 233  user_guide/libraries/pagination.html
  123. 212  user_guide/libraries/parser.html
  124. 138  user_guide/libraries/security.html
  125. 341  user_guide/libraries/sessions.html
  126. 315  user_guide/libraries/table.html
  127. 246  user_guide/libraries/trackback.html
  128. 160  user_guide/libraries/typography.html
  129. 226  user_guide/libraries/unit_testing.html
  130. 252  user_guide/libraries/uri.html
7  .gitignore
@@ -6,4 +6,9 @@ application/cache/*
6 6
 
7 7
 application/logs/*
8 8
 !application/logs/index.html
9  
-!application/logs/.htaccess
  9
+!application/logs/.htaccess
  10
+
  11
+user_guide_src/build/*
  12
+user_guide_src/cilexer/build/*
  13
+user_guide_src/cilexer/dist/*
  14
+user_guide_src/cilexer/pycilexer.egg-info/*
1,451  user_guide/changelog.html
0 additions, 1451 deletions not shown
821  user_guide/database/active_record.html
... ...
@@ -1,821 +0,0 @@
1  
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2  
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3  
-<head>
4  
-
5  
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6  
-<title>Active Record : CodeIgniter User Guide</title>
7  
-
8  
-<style type='text/css' media='all'>@import url('../userguide.css');</style>
9  
-<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
10  
-
11  
-<script type="text/javascript" src="../nav/nav.js"></script>
12  
-<script type="text/javascript" src="../nav/prototype.lite.js"></script>
13  
-<script type="text/javascript" src="../nav/moo.fx.js"></script>
14  
-<script type="text/javascript" src="../nav/user_guide_menu.js"></script>
15  
-
16  
-<meta http-equiv='expires' content='-1' />
17  
-<meta http-equiv= 'pragma' content='no-cache' />
18  
-<meta name='robots' content='all' />
19  
-<meta name='author' content='ExpressionEngine Dev Team' />
20  
-<meta name='description' content='CodeIgniter User Guide' />
21  
-</head>
22  
-<body>
23  
-
24  
-<!-- START NAVIGATION -->
25  
-<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
26  
-<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
27  
-<div id="masthead">
28  
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
29  
-<tr>
30  
-<td><h1>CodeIgniter User Guide Version 2.0.3</h1></td>
31  
-<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
32  
-</tr>
33  
-</table>
34  
-</div>
35  
-<!-- END NAVIGATION -->
36  
-
37  
-
38  
-<!-- START BREADCRUMB -->
39  
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
40  
-<tr>
41  
-<td id="breadcrumb">
42  
-<a href="http://codeigniter.com/">CodeIgniter Home</a> &nbsp;&#8250;&nbsp;
43  
-<a href="../index.html">User Guide Home</a> &nbsp;&#8250;&nbsp;
44  
-<a href="index.html">Database Library</a> &nbsp;&#8250;&nbsp;
45  
-Active Record
46  
-</td>
47  
-<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide&nbsp; <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" />&nbsp;<input type="submit" class="submit" name="sa" value="Go" /></form></td>
48  
-</tr>
49  
-</table>
50  
-<!-- END BREADCRUMB -->
51  
-
52  
-<br clear="all" />
53  
-
54  
-<!-- START CONTENT -->
55  
-<div id="content">
56  
-
57  
-<h1>Active Record Class</h1>
58  
-
59  
-<p>CodeIgniter uses a modified version of the Active Record Database Pattern.
60  
-This pattern allows information to be retrieved, inserted, and updated in your database with minimal scripting.
61  
-In some cases only one or two lines of code are necessary to perform a database action.
62  
-CodeIgniter does not require that each database table be its own class file.  It instead provides a more simplified interface.</p>
63  
-
64  
-<p>Beyond simplicity, a major benefit to using the Active Record features is that it allows you to create database independent applications, since the query syntax
65  
-is generated by each database adapter.  It also allows for safer queries, since the values are escaped automatically by the system.</p>
66  
-
67  
-<p class="important"><strong>Note:</strong>  If you intend to write your own queries you can disable this class in your database config file, allowing the core database library and adapter to utilize fewer resources.<br /></p>
68  
-
69  
-<ul>
70  
-<li><a href="#select">Selecting Data</a></li>
71  
-<li><a href="#insert">Inserting Data</a></li>
72  
-<li><a href="#update">Updating Data</a></li>
73  
-<li><a href="#delete">Deleting Data</a></li>
74  
-<li><a href="#chaining">Method Chaining</a></li>
75  
-<li><a href="#caching">Active Record Caching</a></li>
76  
-</ul>
77  
-
78  
-<h1><a name="select">&nbsp;</a>Selecting Data</h1>
79  
-
80  
-<p>The following functions allow you to build SQL <strong>SELECT</strong> statements.</p>
81  
-
82  
-<h2>$this->db->get();</h2>
83  
-
84  
-<p>Runs the selection query and returns the result.  Can be used by itself to retrieve all records from a table:</p>
85  
-
86  
-<code>$query = $this->db->get('mytable');<br />
87  
-<br />
88  
-// Produces: SELECT * FROM mytable</code>
89  
-
90  
-<p>The second and third parameters enable you to set a limit and offset clause:</p>
91  
-
92  
-<code>$query = $this->db->get('mytable', 10, 20);<br />
93  
-<br />
94  
-// Produces: SELECT * FROM mytable LIMIT 20, 10 (in MySQL. Other databases have slightly different syntax)</code>
95  
-
96  
-<p>You'll notice that the above function is assigned to a variable named <kbd>$query</kbd>, which can be used to show the results:</p>
97  
-
98  
-<code>$query = $this->db->get('mytable');<br />
99  
-<br />
100  
-foreach ($query->result() as $row)<br />
101  
-{<br />
102  
-&nbsp;&nbsp;&nbsp;&nbsp;echo $row->title;<br />
103  
-}</code>
104  
-
105  
-<p>Please visit the <a href="results.html">result functions</a> page for a full discussion regarding result generation.</p>
106  
-
107  
-
108  
-<h2>$this->db->get_where();</h2>
109  
-
110  
-<p>Identical to the above function except that it permits you to add a "where" clause in the second parameter,
111  
-instead of using the db->where() function:</p>
112  
-
113  
-<code>$query = $this->db->get_where('mytable', array('id' => $id), $limit, $offset);</code>
114  
-
115  
-<p>Please read the about the where function below for more information.</p>
116  
-<p class="important">Note: get_where() was formerly known as getwhere(), which has been removed</p>
117  
-
118  
-<h2>$this->db->select();</h2>
119  
-<p>Permits you to write the SELECT portion of your query:</p>
120  
-<p><code>
121  
-$this->db->select('title, content, date');<br />
122  
-<br />
123  
-$query = $this->db->get('mytable');<br />
124  
-<br />
125  
-// Produces: SELECT title, content, date FROM mytable</code></p>
126  
-<p class="important"><strong>Note:</strong> If you are selecting all (*) from a table you do not need to use this function.  When omitted, CodeIgniter assumes you wish to SELECT *</p>
127  
-
128  
-<p>$this-&gt;db-&gt;select() accepts an optional second parameter. If you set it to FALSE, CodeIgniter will not try to protect your field or table names with backticks. This is useful if you need a compound select statement.</p>
129  
-<p><code>$this-&gt;db-&gt;select('(SELECT SUM(payments.amount) FROM payments WHERE payments.invoice_id=4') AS amount_paid', FALSE); <br />
130  
-$query = $this-&gt;db-&gt;get('mytable');<br />
131  
-</code></p>
132  
-<h2>$this->db->select_max();</h2>
133  
-<p>Writes a "SELECT MAX(field)" portion for your query. You can optionally include a second parameter to rename the resulting field.</p>
134  
-<p><code>
135  
-$this->db->select_max('age');<br />
136  
-$query = $this->db->get('members');<br />
137  
-
138  
-// Produces: SELECT MAX(age) as age FROM members<br />
139  
-<br />
140  
-$this-&gt;db-&gt;select_max('age', 'member_age');<br />
141  
-$query = $this-&gt;db-&gt;get('members');<br />
142  
-// Produces: SELECT MAX(age) as member_age FROM members</code></p>
143  
-
144  
-<h2>$this->db->select_min();</h2>
145  
-<p>Writes a "SELECT MIN(field)" portion for your query. As with <dfn>select_max()</dfn>, You can optionally include a second parameter to rename the resulting field.</p>
146  
-<p><code>
147  
-$this->db->select_min('age');<br />
148  
-$query = $this->db->get('members');<br />
149  
-// Produces: SELECT MIN(age) as age FROM members</code></p>
150  
-
151  
-<h2>$this->db->select_avg();</h2>
152  
-<p>Writes a "SELECT AVG(field)" portion for your query. As with <dfn>select_max()</dfn>, You can optionally include a second parameter to rename the resulting field.</p>
153  
-<p><code>
154  
-$this->db->select_avg('age');<br />
155  
-$query = $this->db->get('members');<br />
156  
-// Produces: SELECT AVG(age) as age FROM members</code></p>
157  
-
158  
-<h2>$this->db->select_sum();</h2>
159  
-<p>Writes a "SELECT SUM(field)" portion for your query. As with <dfn>select_max()</dfn>, You can optionally include a second parameter to rename the resulting field.</p>
160  
-<p><code>
161  
-$this->db->select_sum('age');<br />
162  
-$query = $this->db->get('members');<br />
163  
-// Produces: SELECT SUM(age) as age FROM members</code></p>
164  
-
165  
-<h2>$this->db->from();</h2>
166  
-
167  
-<p>Permits you to write the FROM portion of your query:</p>
168  
-
169  
-<code>
170  
-$this->db->select('title, content, date');<br />
171  
-$this->db->from('mytable');<br />
172  
-<br />
173  
-$query = $this->db->get();<br />
174  
-<br />
175  
-// Produces: SELECT title, content, date FROM mytable</code>
176  
-
177  
-<p class="important">Note: As shown earlier, the FROM portion of your query can be specified in the <dfn>$this->db->get()</dfn> function, so use whichever method
178  
-you prefer.</p>
179  
-
180  
-<h2>$this->db->join();</h2>
181  
-
182  
-<p>Permits you to write the JOIN portion of your query:</p>
183  
-
184  
-<code>
185  
-$this->db->select('*');<br />
186  
-$this->db->from('blogs');<br />
187  
-$this->db->join('comments', 'comments.id = blogs.id');<br />
188  
-<br />
189  
-$query = $this->db->get();<br />
190  
-<br />
191  
-// Produces: <br />
192  
-// SELECT * FROM blogs<br />
193  
-// JOIN comments ON comments.id = blogs.id<br />
194  
-</code>
195  
-
196  
-<p>Multiple function calls can be made if you need several joins in one query.</p>
197  
-
198  
-<p>If you need a specific type of JOIN you can specify it via the third parameter of the function.
199  
-Options are: left, right, outer, inner, left outer, and right outer.</p>
200  
-
201  
-<code>
202  
-$this->db->join('comments', 'comments.id = blogs.id', <strong>'left'</strong>);<br />
203  
-<br />
204  
-// Produces: LEFT JOIN comments ON comments.id = blogs.id</code>
205  
-
206  
-
207  
-
208  
-
209  
-
210  
-<h2>$this->db->where();</h2>
211  
-<p>This function enables you to set <strong>WHERE</strong> clauses using one of four methods:</p>
212  
-
213  
-<p class="important"><strong>Note:</strong> All values passed to this function are escaped automatically, producing safer queries.</p>
214  
-
215  
-<ol>
216  
-	<li><strong>Simple key/value method:</strong>
217  
-
218  
-	<code>$this->db->where('name', $name);
219  
-	<br /><br />// Produces: WHERE name = 'Joe'	</code>
220  
-
221  
-	<p>Notice that the equal sign is added for you.</p>
222  
-
223  
-	<p>If you use multiple function calls they will be chained together with <var>AND</var> between them:</p>
224  
-
225  
-	<code>$this->db->where('name', $name);<br />
226  
-	$this->db->where('title', $title);<br />
227  
-	$this->db->where('status', $status);
228  
-	<br /><br />// WHERE name = 'Joe' AND title = 'boss' AND status = 'active'	</code>	</li>
229  
-
230  
-	<li><strong>Custom key/value method:</strong>
231  
-
232  
-	<p>You can include an operator in the first parameter in order to control the comparison:</p>
233  
-
234  
-	<code>$this->db->where('name !=', $name);<br />
235  
-	$this->db->where('id <', $id);
236  
-	<br /><br />// Produces: WHERE name != 'Joe' AND id < 45	</code>	</li>
237  
-	<li><strong>Associative array method:</strong>
238  
-
239  
-
240  
-	<code>
241  
-	$array = array('name' => $name, 'title' => $title, 'status' => $status);<br /><br />
242  
-
243  
-	$this->db->where($array);
244  
-	<br /><br />// Produces: WHERE name = 'Joe' AND title = 'boss' AND status = 'active'	</code>
245  
-
246  
-	<p>You can include your own operators using this method as well:</p>
247  
-
248  
-	<code>
249  
-	$array = array('name !=' => $name, 'id <' => $id, 'date >' => $date);<br /><br />
250  
-
251  
-	$this->db->where($array);</code>	</li>
252  
-		<li><strong>Custom string:</strong>
253  
-
254  
-		<p>You can write your own clauses manually:</p>
255  
-
256  
-		<code>
257  
-		$where = "name='Joe' AND status='boss' OR status='active'";<br /><br />
258  
-		$this->db->where($where);</code></li>
259  
-	</ol>
260  
-
261  
-
262  
-<p>$this-&gt;db-&gt;where() accepts an optional third parameter. If you set it to FALSE, CodeIgniter will not try to protect your field or table names with backticks.</p>
263  
-<p><code>		$this-&gt;db-&gt;where('MATCH (field) AGAINST (&quot;value&quot;)', NULL, FALSE);<br />
264  
-</code></p>
265  
-<h2>$this->db->or_where();</h2>
266  
-<p>This function is identical to the one above, except that multiple instances are joined by OR:</p>
267  
-
268  
-<code>
269  
-$this->db->where('name !=', $name);<br />
270  
-$this->db->or_where('id >', $id);
271  
-<br />
272  
-<br />// Produces: WHERE name != 'Joe' OR id > 50</code>
273  
-
274  
-<p class="important">Note: or_where() was formerly known as orwhere(), which has been removed.</p>
275  
-
276  
-
277  
-<h2>$this->db->where_in();</h2>
278  
-<p>Generates a WHERE field IN ('item', 'item') SQL query joined with  AND if appropriate</p>
279  
-<p><code>
280  
-	$names = array('Frank', 'Todd', 'James');<br />
281  
-	$this->db->where_in('username', $names);<br />
282  
-	// Produces: WHERE username IN ('Frank', 'Todd', 'James')</code></p>
283  
-
284  
-<h2>$this->db->or_where_in();</h2>
285  
-<p>Generates a WHERE field IN ('item', 'item') SQL query joined with OR if appropriate</p>
286  
-<p><code>
287  
-	$names = array('Frank', 'Todd', 'James');<br />
288  
-	$this->db->or_where_in('username', $names);<br />
289  
-	// Produces: OR username IN ('Frank', 'Todd', 'James')</code></p>
290  
-
291  
-<h2>$this->db->where_not_in();</h2>
292  
-<p>Generates a WHERE field NOT IN ('item', 'item') SQL query joined with AND if appropriate</p>
293  
-<p><code>
294  
-	$names = array('Frank', 'Todd', 'James');<br />
295  
-	$this->db->where_not_in('username', $names);<br />
296  
-	// Produces: WHERE username NOT IN ('Frank', 'Todd', 'James')</code></p>
297  
-
298  
-<h2>$this->db->or_where_not_in();</h2>
299  
-<p>Generates a WHERE field NOT IN ('item', 'item') SQL query joined with OR if appropriate</p>
300  
-<p><code>
301  
-	$names = array('Frank', 'Todd', 'James');<br />
302  
-	$this->db->or_where_not_in('username', $names);<br />
303  
-	// Produces: OR username NOT IN ('Frank', 'Todd', 'James')</code></p>
304  
-
305  
-<h2>$this->db->like();</h2>
306  
-<p>This function enables you to generate <strong>LIKE</strong> clauses, useful for doing searches.</p>
307  
-
308  
-<p class="important"><strong>Note:</strong> All values passed to this function are escaped automatically.</p>
309  
-
310  
-
311  
-<ol>
312  
-	<li><strong>Simple key/value method:</strong>
313  
-
314  
-	<code>$this->db->like('title', 'match');
315  
-	<br /><br />// Produces: WHERE title LIKE '%match%'	</code>
316  
-
317  
-	<p>If you use multiple function calls they will be chained together with <var>AND</var> between them:</p>
318  
-
319  
-	<code>$this->db->like('title', 'match');<br />
320  
-	$this->db->like('body', 'match');
321  
-	<br /><br />
322  
-	// WHERE title LIKE '%match%' AND  body LIKE '%match%</code>
323  
-	If you want to control where the wildcard (%) is placed, you can use an optional third argument. Your options are 'before', 'after' and 'both' (which is the default).
324  
-	<code>$this->db->like('title', 'match', 'before');
325  
-	<br />
326  
-		// Produces: WHERE title LIKE '%match'	<br />
327  
-		<br />
328  
-	$this-&gt;db-&gt;like('title', 'match', 'after'); <br />
329  
-// Produces: WHERE title LIKE 'match%' <br />
330  
-<br />
331  
-	$this-&gt;db-&gt;like('title', 'match', 'both'); <br />
332  
-// Produces: WHERE title LIKE '%match%' </code>	</li>
333  
-
334  
-If you do not want to use the wildcard (%) you can pass to the optional third argument the option 'none'.
335  
-
336  
-<code>
337  
-	$this-&gt;db-&gt;like('title', 'match', 'none'); <br />
338  
-// Produces: WHERE title LIKE 'match'
339  
-</code>
340  
-
341  
-	<li><strong>Associative array method:</strong>
342  
-
343  
-	<code>
344  
-	$array = array('title' => $match, 'page1' => $match, 'page2' => $match);<br /><br />
345  
-
346  
-	$this->db->like($array);
347  
-	<br /><br />// WHERE title LIKE '%match%' AND  page1 LIKE '%match%' AND  page2 LIKE '%match%'</code></li>
348  
-	</ol>
349  
-
350  
-
351  
-<h2>$this->db->or_like();</h2>
352  
-<p>This function is identical to the one above, except that multiple instances are joined by OR:</p>
353  
-
354  
-<code>
355  
-$this->db->like('title', 'match');<br />
356  
-$this->db->or_like('body', $match);
357  
-<br />
358  
-<br />// WHERE title LIKE '%match%' OR  body LIKE '%match%'</code>
359  
-
360  
-
361  
-
362  
-
363  
-<p class="important">Note: or_like() was formerly known as orlike(), which has been removed.</p>
364  
-<h2>$this-&gt;db-&gt;not_like();</h2>
365  
-<p>This function is identical to <strong>like()</strong>, except that it generates NOT LIKE statements:</p>
366  
-<code> $this-&gt;db-&gt;not_like('title', 'match');<br />
367  
-<br />
368  
-// WHERE title NOT LIKE '%match%</code>
369  
-<h2>$this-&gt;db-&gt;or_not_like();</h2>
370  
-<p>This function is identical to <strong>not_like()</strong>, except that multiple instances are joined by OR:</p>
371  
-<code> $this-&gt;db-&gt;like('title', 'match');<br />
372  
-$this-&gt;db-&gt;or_not_like('body', 'match'); <br />
373  
-<br />
374  
-// WHERE title  LIKE '%match% OR body NOT LIKE '%match%'</code>
375  
-<h2>$this->db->group_by();</h2>
376  
-<p>Permits you to write the GROUP BY portion of your query:</p>
377  
-
378  
-<code>$this->db->group_by("title");
379  
-<br /><br />// Produces: GROUP BY title
380  
-</code>
381  
-
382  
-<p>You can also pass an array of multiple values as well:</p>
383  
-
384  
-<code>$this->db->group_by(array("title", "date"));
385  
-<br />
386  
-<br />// Produces: GROUP BY title, date</code>
387  
-
388  
-<p class="important">Note: group_by() was formerly known as groupby(), which has been removed. </p>
389  
-
390  
-<h2> $this-&gt;db-&gt;distinct();<br />
391  
-</h2>
392  
-<p>Adds the &quot;DISTINCT&quot; keyword to  a query</p>
393  
-<p><code>$this-&gt;db-&gt;distinct();<br />
394  
-	$this-&gt;db-&gt;get('table');<br />
395  
-		<br />
396  
-	// Produces: SELECT DISTINCT * FROM table</code></p>
397  
-<h2>$this->db->having();</h2>
398  
-<p>Permits you to write the HAVING portion of your query. There are 2 possible syntaxes, 1 argument or 2:</p>
399  
-
400  
-<code>$this->db->having('user_id = 45');
401  
-<br />
402  
-// Produces: HAVING user_id = 45<br />
403  
-<br />
404  
-$this-&gt;db-&gt;having('user_id',  45); <br />
405  
-// Produces: HAVING user_id = 45<br />
406  
-<br />
407  
-</code>
408  
-
409  
-<p>You can also pass an array of multiple values as well:</p>
410  
-
411  
-
412  
-<p><code>$this->db->having(array('title =' => 'My Title', 'id <' => $id)); <br />
413  
-		<br />
414  
-	// Produces: HAVING title = 'My Title', id < 45</code></p>
415  
-<p>If you are using a database that CodeIgniter escapes queries for, you can prevent escaping content by passing an optional third argument, and setting it to FALSE.</p>
416  
-<p><code>$this-&gt;db-&gt;having('user_id',  45); <br />
417  
-// Produces: HAVING `user_id` = 45 in some databases such as MySQL
418  
-		<br />
419  
-		$this-&gt;db-&gt;having('user_id',  45, FALSE); <br />
420  
-// Produces: HAVING user_id = 45</code></p>
421  
-<h2>$this-&gt;db-&gt;or_having();</h2>
422  
-<p>Identical to having(), only separates multiple clauses with &quot;OR&quot;.</p>
423  
-<h2>$this->db->order_by();</h2>
424  
-<p>Lets you set an ORDER BY clause. The first parameter contains the name of the column you would like to order by.
425  
-The second parameter lets you set the direction of the result.  Options are <kbd>asc</kbd> or <kbd>desc</kbd>, or <kbd>random</kbd>. </p>
426  
-
427  
-<code>$this->db->order_by("title", "desc");
428  
-<br />
429  
-<br />// Produces: ORDER BY title DESC
430  
-</code>
431  
-
432  
-<p>You can also pass your own string in the first parameter:</p>
433  
-
434  
-<code>$this->db->order_by('title desc, name asc');
435  
-<br />
436  
-<br />// Produces: ORDER BY title DESC, name ASC
437  
-</code>
438  
-
439  
-<p>Or multiple function calls can be made if you need multiple fields.</p>
440  
-
441  
-<p><code>$this->db->order_by("title", "desc");<br />
442  
-	$this->db->order_by("name", "asc"); <br />
443  
-	<br />
444  
-	// Produces: ORDER BY title DESC, name ASC
445  
-	</code></p>
446  
-<p class="important">Note: order_by() was formerly known as orderby(), which has been removed.</p>
447  
-<p class="important">Note: random ordering is not currently supported in Oracle or MSSQL drivers. These will default to 'ASC'.</p>
448  
-<h2>$this->db->limit();</h2>
449  
-<p>Lets you limit the number of rows you would like returned by the query:</p>
450  
-
451  
-<code>
452  
-$this->db->limit(10);<br />
453  
-<br />
454  
-// Produces: LIMIT 10</code>
455  
-
456  
-
457  
-<p>The second parameter lets you set a result offset.</p>
458  
-
459  
-<code>
460  
-$this->db->limit(10, 20);<br />
461  
-<br />
462  
-// Produces: LIMIT 20, 10 (in MySQL.  Other databases have slightly different syntax)</code>
463  
-
464  
-
465  
-<h2>$this->db->count_all_results();</h2>
466  
-
467  
-<p>Permits you to determine the number of rows in a particular Active Record query. Queries will accept Active Record restrictors such as where(),  or_where(), like(), or_like(), etc. Example:</p>
468  
-<code>echo $this->db->count_all_results('<var>my_table</var>');<br />
469  
-
470  
-// Produces an integer, like 25<br />
471  
-<br />
472  
-$this-&gt;db-&gt;like('title', 'match');<br />
473  
-$this-&gt;db-&gt;from('<var>my_table</var>');<br />
474  
-echo $this-&gt;db-&gt;count_all_results();<br />
475  
-// Produces an integer, like 17 </code>
476  
-
477  
-<h2>$this->db->count_all();</h2>
478  
-
479  
-<p>Permits you to determine the number of rows in a particular table.  Submit the table name in the first parameter. Example:</p>
480  
-
481  
-<code>echo $this->db->count_all('<var>my_table</var>');<br />
482  
-<br />
483  
-// Produces an integer, like 25</code>
484  
-
485  
-
486  
-
487  
-<a name="insert">&nbsp;</a>
488  
-<h1>Inserting Data</h1>
489  
-
490  
-<h2>$this->db->insert();</h2>
491  
-<p>Generates an insert string based on the data you supply, and runs the query. You can either pass an
492  
-<strong>array</strong> or an <strong>object</strong> to the function.  Here is an example using an array:</p>
493  
-
494  
-<code>
495  
-$data = array(<br />
496  
-&nbsp;&nbsp;&nbsp;'title' => 'My title' ,<br />
497  
-&nbsp;&nbsp;&nbsp;'name' => 'My Name' ,<br />
498  
-&nbsp;&nbsp;&nbsp;'date' => 'My date'<br />
499  
-);<br />
500  
-<br />
501  
-$this->db->insert('mytable', $data);
502  
-<br /><br />
503  
-// Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date')</code>
504  
-
505  
-<p>The first parameter will contain the table name, the second is an associative array of values.</p>
506  
-
507  
-<p>Here is an example using an object:</p>
508  
-
509  
-<code>
510  
-/*<br />
511  
-&nbsp;&nbsp;&nbsp;&nbsp;class Myclass {<br />
512  
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var  $title = 'My Title';<br />
513  
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var  $content = 'My Content';<br />
514  
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var  $date = 'My Date';<br />
515  
-&nbsp;&nbsp;&nbsp;&nbsp;}<br />
516  
-*/<br />
517  
-<br />
518  
-$object = new Myclass;<br />
519  
-<br />
520  
-$this->db->insert('mytable', $object);
521  
-<br /><br />
522  
-// Produces: INSERT INTO mytable (title, content, date) VALUES ('My Title', 'My Content', 'My Date')</code>
523  
-
524  
-<p>The first parameter will contain the table name, the second is an object.</p>
525  
-
526  
-<p class="important"><strong>Note:</strong> All values are escaped automatically producing safer queries.</p>
527  
-
528  
-<h2>$this->db->insert_batch();</h2>
529  
-<p>Generates an insert string based on the data you supply, and runs the query. You can either pass an
530  
-<strong>array</strong> or an <strong>object</strong> to the function.  Here is an example using an array:</p>
531  
-
532  
-<code>
533  
-$data = array(<br />
534  
-&nbsp;&nbsp;&nbsp;array(<br />
535  
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'title' => 'My title' ,<br />
536  
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'name' => 'My Name' ,<br />
537  
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'date' => 'My date'<br />
538  
-&nbsp;&nbsp;&nbsp;),<br />
539  
-&nbsp;&nbsp;&nbsp;array(<br />
540  
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'title' => 'Another title' ,<br />
541  
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'name' => 'Another Name' ,<br />
542  
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'date' => 'Another date'<br />
543  
-&nbsp;&nbsp;&nbsp;)<br />
544  
-);<br />
545  
-<br />
546  
-$this->db->insert_batch('mytable', $data);
547  
-<br /><br />
548  
-// Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date'),  ('Another title', 'Another name', 'Another date')</code>
549  
-
550  
-<p>The first parameter will contain the table name, the second is an associative array of values.</p>
551  
-
552  
-<p class="important"><strong>Note:</strong> All values are escaped automatically producing safer queries.</p>
553  
-
554  
-
555  
-
556  
-<h2>$this->db->set();</h2>
557  
-<p>This function enables you to set values for <dfn>inserts</dfn> or <dfn>updates</dfn>.</p>
558  
-
559  
-<p><strong>It can be used instead of passing a data array directly to the insert or update functions:</strong> </p>
560  
-
561  
-<code>$this->db->set('name', $name);
562  
-<br />
563  
-$this->db->insert('mytable');
564  
-<br /><br />
565  
-// Produces: INSERT INTO mytable (name) VALUES ('{$name}')</code>
566  
-
567  
-<p>If you use multiple function called they will be assembled properly based on whether you are doing an insert or an update:</p>
568  
-
569  
-<code>$this-&gt;db-&gt;set('name', $name);<br />
570  
-$this-&gt;db-&gt;set('title', $title);<br />
571  
-$this-&gt;db-&gt;set('status', $status);<br />
572  
-$this-&gt;db-&gt;insert('mytable'); </code>
573  
-<p><strong>set()</strong> will also accept an optional third parameter ($escape), that will prevent data from being escaped if set to FALSE. To illustrate the difference, here is set() used both with and without the escape parameter.</p>
574  
-<p><code>$this-&gt;db-&gt;set('field', 'field+1', FALSE);<br />
575  
-	$this-&gt;db-&gt;insert('mytable'); <br />
576  
-	// gives INSERT INTO mytable (field) VALUES (field+1)<br />
577  
-	<br />
578  
-	$this-&gt;db-&gt;set('field', 'field+1');<br />
579  
-	$this-&gt;db-&gt;insert('mytable'); <br />
580  
-	// gives INSERT INTO mytable (field) VALUES ('field+1')</code></p>
581  
-<p>You can also pass an associative array to this function:</p>
582  
-<code>
583  
-$array = array('name' => $name, 'title' => $title, 'status' => $status);<br /><br />
584  
-
585  
-$this->db->set($array);<br />
586  
-$this->db->insert('mytable');
587  
-</code>
588  
-
589  
-<p>Or an object:</p>
590  
-
591  
-
592  
-<code>
593  
-/*<br />
594  
-&nbsp;&nbsp;&nbsp;&nbsp;class Myclass {<br />
595  
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var  $title = 'My Title';<br />
596  
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var  $content = 'My Content';<br />
597  
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var  $date = 'My Date';<br />
598  
-&nbsp;&nbsp;&nbsp;&nbsp;}<br />
599  
-*/<br />
600  
-<br />
601  
-$object = new Myclass;<br />
602  
-<br />
603  
-$this->db->set($object);<br />
604  
-$this->db->insert('mytable');
605  
-</code>
606  
-
607  
-
608  
-
609  
-<a name="update">&nbsp;</a>
610  
-<h1>Updating Data</h1>
611  
-
612  
-<h2>$this->db->update();</h2>
613  
-<p>Generates an update string and runs the query based on the data you supply.  You can pass an
614  
-<strong>array</strong> or an <strong>object</strong> to the function. Here is an example using
615  
-an array:</p>
616  
-
617  
-<code>
618  
-$data = array(<br />
619  
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'title' => $title,<br />
620  
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'name' => $name,<br />
621  
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'date' => $date<br />
622  
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);<br />
623  
-<br />
624  
-$this->db->where('id', $id);<br />
625  
-$this->db->update('mytable', $data);
626  
-<br /><br />
627  
-// Produces:<br />
628  
-// UPDATE mytable <br />
629  
-// SET title = '{$title}', name = '{$name}', date = '{$date}'<br />
630  
-// WHERE id = $id</code>
631  
-
632  
-<p>Or you can supply an object:</p>
633  
-
634  
-<code>
635  
-/*<br />
636  
-&nbsp;&nbsp;&nbsp;&nbsp;class Myclass {<br />
637  
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var  $title = 'My Title';<br />
638  
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var  $content = 'My Content';<br />
639  
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var  $date = 'My Date';<br />
640  
-&nbsp;&nbsp;&nbsp;&nbsp;}<br />
641  
-*/<br />
642  
-<br />
643  
-$object = new Myclass;<br />
644  
-<br />
645  
-$this->db->where('id', $id);<br />
646  
-$this->db->update('mytable', $object);
647  
-<br />
648  
-<br />
649  
-// Produces:<br />
650  
-// UPDATE mytable <br />
651  
-// SET title = '{$title}', name = '{$name}', date = '{$date}'<br />
652  
-// WHERE id = $id</code>
653  
-
654  
-
655  
-
656  
-<p class="important"><strong>Note:</strong> All values are escaped automatically producing safer queries.</p>
657  
-
658  
-<p>You'll notice the use of the <dfn>$this->db->where()</dfn> function, enabling you to set the WHERE clause.
659  
-You can optionally pass this information directly into the update function as a string:</p>
660  
-
661  
-<code>$this->db->update('mytable', $data, "id = 4");</code>
662  
-
663  
-<p>Or as an array:</p>
664  
-
665  
-<code>$this->db->update('mytable', $data, array('id' => $id));</code>
666  
-
667  
-<p>You may also use the <dfn>$this->db->set()</dfn> function described above when performing updates.</p>
668  
-
669  
-<h2>$this->db->update_batch();</h2>
670  
-<p>Generates an update string based on the data you supply, and runs the query. You can either pass an
671  
-<strong>array</strong> or an <strong>object</strong> to the function.  Here is an example using an array:</p>
672  
-
673  
-<code>
674  
-$data = array(<br/>
675  
-&nbsp;&nbsp;&nbsp;array(<br />
676  
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'title' => 'My title' ,<br />
677  
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'name' => 'My Name 2' ,<br />
678  
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'date' => 'My date 2'<br />
679  
-&nbsp;&nbsp;&nbsp;),<br />
680  
-&nbsp;&nbsp;&nbsp;array(<br />
681  
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'title' => 'Another title' ,<br />
682  
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'name' => 'Another Name 2' ,<br />
683  
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'date' => 'Another date 2'<br />
684  
-&nbsp;&nbsp;&nbsp;)<br/>
685  
-);<br />
686  
-<br />
687  
-$this->db->update_batch('mytable', $data, 'title');
688  
-<br /><br />
689  
-// Produces: <br />
690  
-// UPDATE `mytable` SET `name` = CASE<br />
691  
-// WHEN `title` = 'My title' THEN 'My Name 2'<br />
692  
-// WHEN `title` = 'Another title' THEN 'Another Name 2'<br />
693  
-// ELSE `name` END,<br />
694  
-// `date` = CASE <br />
695  
-// WHEN `title` = 'My title' THEN 'My date 2'<br />
696  
-// WHEN `title` = 'Another title' THEN 'Another date 2'<br />
697  
-// ELSE `date` END<br />
698  
-// WHERE `title` IN ('My title','Another title')</code>
699  
-
700  
-<p>The first parameter will contain the table name, the second is an associative array of values, the third parameter is the where key.</p>
701  
-
702  
-<p class="important"><strong>Note:</strong> All values are escaped automatically producing safer queries.</p>
703  
-
704  
-
705  
-<a name="delete">&nbsp;</a>
706  
-<h1>Deleting Data</h1>
707  
-
708  
-
709  
-
710  
-<h2>$this->db->delete();</h2>
711  
-<p>Generates a delete SQL string and runs the query.</p>
712  
-
713  
-<code>
714  
-$this->db->delete('mytable', array('id' => $id));
715  
-<br /><br />
716  
-// Produces:<br />
717  
-// DELETE FROM mytable <br />
718  
-// WHERE id = $id</code>
719  
-
720  
-<p>The first parameter is the table name, the second is the where clause. You can also use the <dfn>where()</dfn> or <dfn>or_where()</dfn> functions instead of passing
721  
-the data to the second parameter of the function:</p>
722  
-
723  
-<p><code> $this->db->where('id', $id);<br />
724  
-	$this->db->delete('mytable'); <br />
725  
-	<br />
726  
-	// Produces:<br />
727  
-	// DELETE FROM mytable <br />
728  
-	// WHERE id = $id</code></p>
729  
-<p>An array of table names can be passed into delete() if you would like to delete data from more than 1 table.</p>
730  
-<p><code>$tables = array('table1', 'table2', 'table3');<br />
731  
-$this-&gt;db-&gt;where('id', '5');<br />
732  
-$this-&gt;db-&gt;delete($tables);</code></p>
733  
-<p>If you want to delete all data from a table, you can use the <dfn>truncate()</dfn> function, or <dfn>empty_table()</dfn>.</p>
734  
-<h2>$this-&gt;db-&gt;empty_table();</h2>
735  
-<p>Generates a delete SQL string and runs the query.<code>	$this-&gt;db-&gt;empty_table('mytable'); <br />
736  
-	<br />
737  
-// Produces<br />
738  
-// DELETE FROM mytable</code></p>
739  
-<h2>$this-&gt;db-&gt;truncate();</h2>
740  
-<p>Generates a truncate SQL string and runs the query.</p>
741  
-<code> $this-&gt;db-&gt;from('mytable'); <br />
742  
-$this-&gt;db-&gt;truncate(); <br />
743  
-// or <br />
744  
-$this-&gt;db-&gt;truncate('mytable'); <br />
745  
-<br />
746  
-// Produce:<br />
747  
-// TRUNCATE mytable <br />
748  
-</code>
749  
-<p class="important"><strong>Note:</strong> If the TRUNCATE command isn't available, truncate() will execute as &quot;DELETE FROM table&quot;.</p>
750  
-
751  
-<h1><a name="chaining">&nbsp;</a>Method Chaining</h1>
752  
-
753  
-<p>Method chaining allows you to simplify your syntax by connecting multiple functions.  Consider this example:</p>
754  
-
755  
-<code>
756  
-<dfn>$this->db</dfn><kbd>-></kbd><var>select</var>('title')<kbd>-></kbd><var>from</var>('mytable')<kbd>-></kbd><var>where</var>('id', $id)<kbd>-></kbd><var>limit</var>(10, 20);<br />
757  
-<br />
758  
-$query = $this->db->get();</code>
759  
-
760  
-<p class="important"><strong>Note:</strong> Method chaining only works with PHP 5.</p>
761  
-
762  
-<p>&nbsp;</p>
763  
-
764  
-<h1><a name="caching">&nbsp;</a>Active Record Caching</h1>
765  
-
766  
-<p>While not &quot;true&quot; caching, Active Record enables you to save (or &quot;cache&quot;) certain parts of your queries for reuse at a later point in your script's execution. Normally, when an Active Record call is completed, all stored information is reset for the next call. With caching, you can prevent this reset, and reuse information easily.</p>
767  
-
768  
-<p>Cached calls are cumulative. If you make 2 cached select() calls, and then 2 uncached select() calls, this will result in 4 select() calls. There are three Caching functions available:</p>
769  
-
770  
-<h2>$this-&gt;db-&gt;start_cache()</h2>
771  
-
772  
-<p>This function must be called to begin caching. All Active Record queries of the correct type (see below for supported queries) are stored for later use.</p>
773  
-
774  
-<h2>$this-&gt;db-&gt;stop_cache()</h2>
775  
-
776  
-<p>This function can be called to stop caching.</p>
777  
-
778  
-<h2>$this-&gt;db-&gt;flush_cache()</h2>
779  
-
780  
-<p>This function deletes all items from the Active Record cache.</p>
781  
-
782  
-<p>Here's a usage example:</p>
783  
-
784  
-<p><code>$this-&gt;db-&gt;start_cache();<br />
785  
-$this-&gt;db-&gt;select('field1');<br />
786  
-$this-&gt;db-&gt;stop_cache();<br /><br />
787  
-$this-&gt;db-&gt;get('tablename');<br />
788  
-<br />
789  
-//Generates: SELECT `field1` FROM (`tablename`)<br />
790  
-<br />
791  
-$this-&gt;db-&gt;select('field2');<br />
792  
-$this-&gt;db-&gt;get('tablename');<br />
793  
-<br />
794  
-//Generates:  SELECT `field1`, `field2` FROM (`tablename`)<br />
795  
-<br />
796  
-$this-&gt;db-&gt;flush_cache();<br />
797  
-<br />
798  
-$this-&gt;db-&gt;select('field2');<br />
799  
-$this-&gt;db-&gt;get('tablename');<br />
800  
-<br />
801  
-//Generates:  SELECT `field2` FROM (`tablename`)</code></p>
802  
-
803  
-<p class="important"> <strong>Note:</strong> The following statements can be cached: select, from, join, where, like, group_by, having, order_by, set</p>
804  
-<p>&nbsp;</p>
805  
-</div>
806  
-<!-- END CONTENT -->
807  
-
808  
-
809  
-<div id="footer">
810  
-<p>
811  
-Previous Topic:&nbsp;&nbsp;<a href="helpers.html">Query Helper Functions</a>
812  
-&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
813  
-<a href="#top">Top of Page</a>&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
814  
-<a href="../index.html">User Guide Home</a>&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
815  
-Next Topic:&nbsp;&nbsp;<a href="transactions.html">Transactions</a>
816  
-</p>
817  
-<p><a href="http://codeigniter.com">CodeIgniter</a> &nbsp;&middot;&nbsp; Copyright &#169; 2006 - 2011 &nbsp;&middot;&nbsp; <a href="http://ellislab.com/">EllisLab, Inc.</a></p>
818  
-</div>
819  
-
820  
-</body>
821  
-</html>
220  user_guide/database/caching.html
... ...
@@ -1,220 +0,0 @@
1  
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2  
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3  
-<head>
4  
-
5  
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6  
-<title>Database Caching Class : CodeIgniter User Guide</title>
7  
-
8  
-<style type='text/css' media='all'>@import url('../userguide.css');</style>
9  
-<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
10  
-
11  
-<script type="text/javascript" src="../nav/nav.js"></script>
12  
-<script type="text/javascript" src="../nav/prototype.lite.js"></script>
13  
-<script type="text/javascript" src="../nav/moo.fx.js"></script>
14  
-<script type="text/javascript" src="../nav/user_guide_menu.js"></script>
15  
-
16  
-<meta http-equiv='expires' content='-1' />
17  
-<meta http-equiv= 'pragma' content='no-cache' />
18  
-<meta name='robots' content='all' />
19  
-<meta name='author' content='ExpressionEngine Dev Team' />
20  
-<meta name='description' content='CodeIgniter User Guide' />
21  
-
22  
-</head>
23  
-<body>
24  
-
25  
-<!-- START NAVIGATION -->
26  
-<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
27  
-<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
28  
-<div id="masthead">
29  
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
30  
-<tr>
31  
-<td><h1>CodeIgniter User Guide Version 2.0.3</h1></td>
32  
-<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
33  
-</tr>
34  
-</table>
35  
-</div>
36  
-<!-- END NAVIGATION -->
37  
-
38  
-
39  
-<!-- START BREADCRUMB -->
40  
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
41  
-<tr>
42  
-<td id="breadcrumb">
43  
-<a href="http://codeigniter.com/">CodeIgniter Home</a> &nbsp;&#8250;&nbsp;
44  
-<a href="../index.html">User Guide Home</a> &nbsp;&#8250;&nbsp;
45  
-<a href="index.html">Database Library</a> &nbsp;&#8250;&nbsp;
46  
-Database Caching Class
47  
-</td>
48  
-<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide&nbsp; <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" />&nbsp;<input type="submit" class="submit" name="sa" value="Go" /></form></td>
49  
-</tr>
50  
-</table>
51  
-<!-- END BREADCRUMB -->
52  
-
53  
-
54  
-<br clear="all" />
55  
-
56  
-
57  
-<!-- START CONTENT -->
58  
-<div id="content">
59  
-
60  
-<h1>Database Caching Class</h1>
61  
-
62  
-<p>The Database Caching Class permits you to cache your queries as text files for reduced database load.</p>
63  
-
64  
-<p class="important"><strong>Important:</strong>&nbsp; This class is initialized automatically by the database driver
65  
-when caching is enabled.  Do NOT load this class manually.<br /><br />
66  
-
67  
-<strong>Also note:</strong>&nbsp; Not all query result functions are available when you use caching. Please read this page carefully.</p>
68  
-
69  
-<h2>Enabling Caching</h2>
70  
-
71  
-<p>Caching is enabled in three steps:</p>
72  
-
73  
-<ul>
74  
-<li>Create a writable directory on your server where the cache files can be stored.</li>
75  
-<li>Set the path to your cache folder in your <dfn>application/config/database.php</dfn> file.</li>
76  
-<li>Enable the caching feature, either globally by setting the preference in your <dfn>application/config/database.php</dfn> file, or manually as described below.</li>
77  
-</ul>
78  
-
79  
-<p>Once enabled, caching will happen automatically whenever a page is loaded that contains database queries.</p>
80  
-
81  
-
82  
-<h2>How Does Caching Work?</h2>
83  
-
84  
-<p>CodeIgniter's query caching system happens dynamically when your pages are viewed.
85  
-When caching is enabled, the first time a web page is loaded, the query result object will
86  
-be serialized and stored in a text file on your server. The next time the page is loaded the cache file will be used instead of
87  
-accessing your database.  Your database usage can effectively be reduced to zero for any pages that have been cached.</p>
88  
-
89  
-<p>Only <dfn>read-type</dfn> (SELECT) queries can be cached, since these are the only type of queries that produce a result.
90  
-<dfn>Write-type</dfn> (INSERT, UPDATE, etc.) queries, since they don't generate a result, will not be cached by the system.</p>
91  
-
92  
-<p>Cache files DO NOT expire.  Any queries that have been cached will remain cached until you delete them.  The caching system
93  
-permits you clear caches associated with individual pages, or you can delete the entire collection of cache files.
94  
-Typically you'll want to use the housekeeping functions described below to delete cache files after certain
95  
-events take place, like when you've added new information to your database.</p>
96  
-
97  
-<h2>Will Caching Improve Your Site's Performance?</h2>
98  
-
99  
-<p>Getting a performance gain as a result of caching depends on many factors.
100  
-If you have a highly optimized database under very little load, you probably won't see a performance boost.
101  
-If your database is under heavy use you probably will see an improved response, assuming your file-system is not
102  
-overly taxed.  Remember that caching simply changes how your information is retrieved, shifting it from being a database
103  
-operation to a file-system one.</p>
104  
-
105  
-<p>In some clustered server environments, for example, caching may be detrimental since file-system operations are so intense.
106  
-On single servers in shared environments, caching will probably be beneficial. Unfortunately there is no
107  
-single answer to the question of whether you should cache your database.  It really depends on your situation.</p>
108  
-
109  
-<h2>How are Cache Files Stored?</h2>
110  
-
111  
-<p>CodeIgniter places the result of EACH query into its own cache file.  Sets of cache files are further organized into
112  
-sub-folders corresponding to your controller functions.  To be precise, the sub-folders are named identically to the
113  
-first two segments of your URI (the controller class name and function name).</p>
114  
-
115  
-<p>For example, let's say you have a controller called <dfn>blog</dfn> with a function called <dfn>comments</dfn> that
116  
-contains three queries.  The caching system will create a cache folder
117  
-called <kbd>blog+comments</kbd>, into which it will write three cache files.</p>
118  
-
119  
-<p>If you use dynamic queries that change based on information in your URI (when using pagination, for example), each instance of
120  
-the query will produce its own cache file.  It's possible, therefore, to end up with many times more cache files than you have
121  
-queries.</p>
122  
-
123  
-
124  
-<h2>Managing your Cache Files</h2>
125  
-
126  
-<p>Since cache files do not expire, you'll need to build deletion routines into your application.  For example, let's say you have a blog
127  
-that allows user commenting.  Whenever a new comment is submitted you'll want to delete the cache files associated with the
128  
-controller function that serves up your comments.  You'll find two delete functions described below that help you
129  
-clear data.</p>
130  
-
131  
-
132  
-<h2>Not All Database Functions Work with Caching</h2>
133  
-
134  
-<p>Lastly, we need to point out that the result object that is cached is a simplified version of the full result object. For that reason,
135  
-some of the query result functions are not available for use.</p>
136  
-
137  
-<p>The following functions <kbd>ARE NOT</kbd> available when using a cached result object:</p>
138  
-
139  
-<ul>
140  
-<li>num_fields()</li>
141  
-<li>field_names()</li>
142  
-<li>field_data()</li>
143  
-<li>free_result()</li>
144  
-</ul>
145  
-
146  
-<p>Also, the two database resources (result_id and conn_id) are not available when caching, since result resources only
147  
-pertain to run-time operations.</p>
148  
-
149  
-
150  
-<br />
151  
-
152  
-<h1>Function Reference</h1>
153  
-
154  
-
155  
-
156  
-<h2>$this->db->cache_on()&nbsp; / &nbsp; $this->db->cache_off()</h2>
157  
-
158  
-<p>Manually enables/disables caching.  This can be useful if you want to
159  
-keep certain queries from being cached.  Example:</p>
160  
-
161  
-<code>
162  
-// Turn caching on<br />
163  
-$this->db->cache_on();<br />
164  
-$query = $this->db->query("SELECT * FROM mytable");<br />
165  
-<br />
166  
-// Turn caching off for this one query<br />
167  
-$this->db->cache_off();<br />
168  
-$query = $this->db->query("SELECT * FROM members WHERE member_id = '$current_user'");<br />
169  
-<br />
170  
-// Turn caching back on<br />
171  
-$this->db->cache_on();<br />
172  
-$query = $this->db->query("SELECT * FROM another_table");
173  
-</code>
174  
-
175  
-
176  
-<h2>$this->db->cache_delete()</h2>
177  
-
178  
-<p>Deletes the cache files associated with a particular page. This is useful if you need to clear caching after you update your database.</p>
179  
-
180  
-<p>The caching system saves your cache files to folders that correspond to the URI of the page you are viewing.  For example, if you are viewing
181  
-a page at <dfn>example.com/index.php/blog/comments</dfn>, the caching system will put all cache files associated with it in a folder
182  
-called <dfn>blog+comments</dfn>.  To delete those particular cache files you will use:</p>
183  
-
184  
-<code>$this->db->cache_delete('blog', 'comments');</code>
185  
-
186  
-<p>If you do not use any parameters the current URI will be used when determining what should be cleared.</p>
187  
-
188  
-
189  
-<h2>$this->db->cache_delete_all()</h2>
190  
-
191  
-<p>Clears all existing cache files.  Example:</p>
192  
-
193  
-<code>$this->db->cache_delete_all();</code>
194  
-
195  
-
196  
-
197  
-
198  
-
199  
-
200  
-
201  
-
202  
-
203  
-