diff options
-rw-r--r-- | user_guide/database/results.html | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/user_guide/database/results.html b/user_guide/database/results.html index 8e8d3cf96..bea00caea 100644 --- a/user_guide/database/results.html +++ b/user_guide/database/results.html @@ -203,6 +203,27 @@ echo $query->num_fields(); +<h2>$query->free_result()</h2>
+<p>It frees the memory associated with the result and deletes the result resource ID. Normally PHP frees its memory automatically at the end of script
+execution. However, if you are running a lot of queries in a particular script you might want to free the result after each query result has been
+generated in order to cut down on memory consumptions. Example:
+</p>
+
+<code>$query = $this->db->query('SELECT title FROM my_table');<br /><br />
+foreach ($query->result() as $row)<br />
+{<br />
+ echo $row->title;<br />
+}<br />
+$query->free_result(); // The $query result object will no longer be available<br />
+<br />
+$query2 = $this->db->query('SELECT name FROM some_table');<br /><br />
+$row = $query2->row();<br />
+echo $row->name;<br />
+$query2->free_result(); // The $query2 result object will no longer be available
+</code>
+
+
+
</div>
|