summaryrefslogtreecommitdiffstats
path: root/user_guide/database/active_record.html
diff options
context:
space:
mode:
Diffstat (limited to 'user_guide/database/active_record.html')
-rw-r--r--user_guide/database/active_record.html74
1 files changed, 37 insertions, 37 deletions
diff --git a/user_guide/database/active_record.html b/user_guide/database/active_record.html
index 482115ccd..065db4913 100644
--- a/user_guide/database/active_record.html
+++ b/user_guide/database/active_record.html
@@ -220,20 +220,20 @@ $this->db->join('comments', 'comments.id = blogs.id', <strong>'left'</strong>);<
<code>$this->db->where('name', $name);
<br /><br />// Produces: WHERE name = 'Joe' </code>
-
+
<p>Notice that the equal sign is added for you.</p>
-
+
<p>If you use multiple function calls they will be chained together with <var>AND</var> between them:</p>
-
+
<code>$this->db->where('name', $name);<br />
$this->db->where('title', $title);<br />
$this->db->where('status', $status);
<br /><br />// WHERE name = 'Joe' AND title = 'boss' AND status = 'active' </code> </li>
-
+
<li><strong>Custom key/value method:</strong>
-
+
<p>You can include an operator in the first parameter in order to control the comparison:</p>
-
+
<code>$this->db->where('name !=', $name);<br />
$this->db->where('id <', $id);
<br /><br />// Produces: WHERE name != 'Joe' AND id < 45 </code> </li>
@@ -242,7 +242,7 @@ $this->db->join('comments', 'comments.id = blogs.id', <strong>'left'</strong>);<
<code>
$array = array('name' => $name, 'title' => $title, 'status' => $status);<br /><br />
-
+
$this->db->where($array);
<br /><br />// Produces: WHERE name = 'Joe' AND title = 'boss' AND status = 'active' </code>
@@ -250,10 +250,10 @@ $this->db->join('comments', 'comments.id = blogs.id', <strong>'left'</strong>);<
<code>
$array = array('name !=' => $name, 'id <' => $id, 'date >' => $date);<br /><br />
-
+
$this->db->where($array);</code> </li>
<li><strong>Custom string:</strong>
-
+
<p>You can write your own clauses manually:</p>
<code>
@@ -263,7 +263,7 @@ $this->db->join('comments', 'comments.id = blogs.id', <strong>'left'</strong>);<
<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>
-<p><code> $this-&gt;db-&gt;where('MATCH (field) AGAINST (&quot;value&quot;)', NULL, FALSE);<br />
+<p><code> $this-&gt;db-&gt;where('MATCH (field) AGAINST (&quot;value&quot;)', NULL, FALSE);<br />
</code></p>
<h2>$this->db->or_where();</h2>
<p>This function is identical to the one above, except that multiple instances are joined by OR:</p>
@@ -290,7 +290,7 @@ $this->db->or_where('id >', $id);
$names = array('Frank', 'Todd', 'James');<br />
$this->db->or_where_in('username', $names);<br />
// Produces: OR username IN ('Frank', 'Todd', 'James')</code></p>
-
+
<h2>$this->db->where_not_in();</h2>
<p>Generates a WHERE field NOT IN ('item', 'item') SQL query joined with AND if appropriate</p>
<p><code>
@@ -316,14 +316,14 @@ $this->db->or_where('id >', $id);
<code>$this->db->like('title', 'match');
<br /><br />// Produces: WHERE title LIKE '%match%' </code>
-
+
<p>If you use multiple function calls they will be chained together with <var>AND</var> between them:</p>
-
+
<code>$this->db->like('title', 'match');<br />
$this->db->like('body', 'match');
<br /><br />
// WHERE title LIKE '%match%' AND body LIKE '%match%</code>
- 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).
+ 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).
<code>$this->db->like('title', 'match', 'before');
<br />
// Produces: WHERE title LIKE '%match' <br />
@@ -333,17 +333,17 @@ $this->db->or_where('id >', $id);
<br />
$this-&gt;db-&gt;like('title', 'match', 'both'); <br />
// Produces: WHERE title LIKE '%match%' </code> </li>
-
+
<li><strong>Associative array method:</strong>
<code>
$array = array('title' => $match, 'page1' => $match, 'page2' => $match);<br /><br />
-
+
$this->db->like($array);
<br /><br />// WHERE title LIKE '%match%' AND page1 LIKE '%match%' AND page2 LIKE '%match%'</code></li>
</ol>
-
-
+
+
<h2>$this->db->or_like();</h2>
<p>This function is identical to the one above, except that multiple instances are joined by OR:</p>
@@ -355,7 +355,7 @@ $this->db->or_like('body', $match);
-
+
<p class="important">Note: or_like() was formerly known as orlike(), which has been removed.</p>
<h2>$this-&gt;db-&gt;not_like();</h2>
<p>This function is identical to <strong>like()</strong>, except that it generates NOT LIKE statements:</p>
@@ -370,17 +370,17 @@ $this-&gt;db-&gt;or_not_like('body', 'match'); <br />
// WHERE title LIKE '%match% OR body NOT LIKE '%match%'</code>
<h2>$this->db->group_by();</h2>
<p>Permits you to write the GROUP BY portion of your query:</p>
-
+
<code>$this->db->group_by("title");
<br /><br />// Produces: GROUP BY title
</code>
<p>You can also pass an array of multiple values as well:</p>
-
+
<code>$this->db->group_by(array("title", "date"));
<br />
<br />// Produces: GROUP BY title, date</code>
-
+
<p class="important">Note: group_by() was formerly known as groupby(), which has been removed. </p>
<h2> $this-&gt;db-&gt;distinct();<br />
@@ -392,7 +392,7 @@ $this-&gt;db-&gt;or_not_like('body', 'match'); <br />
// Produces: SELECT DISTINCT * FROM table</code></p>
<h2>$this->db->having();</h2>
<p>Permits you to write the HAVING portion of your query. There are 2 possible syntaxes, 1 argument or 2:</p>
-
+
<code>$this->db->having('user_id = 45');
<br />
// Produces: HAVING user_id = 45<br />
@@ -401,7 +401,7 @@ $this-&gt;db-&gt;having('user_id', 45); <br />
// Produces: HAVING user_id = 45<br />
<br />
</code>
-
+
<p>You can also pass an array of multiple values as well:</p>
@@ -419,14 +419,14 @@ $this-&gt;db-&gt;having('user_id', 45); <br />
<h2>$this->db->order_by();</h2>
<p>Lets you set an ORDER BY clause. The first parameter contains the name of the column you would like to order by.
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>
-
+
<code>$this->db->order_by("title", "desc");
<br />
<br />// Produces: ORDER BY title DESC
</code>
<p>You can also pass your own string in the first parameter:</p>
-
+
<code>$this->db->order_by('title desc, name asc');
<br />
<br />// Produces: ORDER BY title DESC, name ASC
@@ -479,10 +479,10 @@ echo $this-&gt;db-&gt;count_all_results();<br />
// Produces an integer, like 25</code>
-
+
<a name="insert">&nbsp;</a>
<h1>Inserting Data</h1>
-
+
<h2>$this->db->insert();</h2>
<p>Generates an insert string based on the data you supply, and runs the query. You can either pass an
<strong>array</strong> or an <strong>object</strong> to the function. Here is an example using an array:</p>
@@ -520,9 +520,9 @@ $this->db->insert('mytable', $object);
<p>The first parameter will contain the table name, the second is an associative array of values.</p>
<p class="important"><strong>Note:</strong> All values are escaped automatically producing safer queries.</p>
-
-
-
+
+
+
<h2>$this->db->set();</h2>
<p>This function enables you to set values for <dfn>inserts</dfn> or <dfn>updates</dfn>.</p>
@@ -576,10 +576,10 @@ $this->db->insert('mytable');
</code>
-
+
<a name="update">&nbsp;</a>
<h1>Updating Data</h1>
-
+
<h2>$this->db->update();</h2>
<p>Generates an update string and runs the query based on the data you supply. You can pass an
<strong>array</strong> or an <strong>object</strong> to the function. Here is an example using
@@ -625,7 +625,7 @@ $this->db->update('mytable', $object);
<p class="important"><strong>Note:</strong> All values are escaped automatically producing safer queries.</p>
-
+
<p>You'll notice the use of the <dfn>$this->db->where()</dfn> function, enabling you to set the WHERE clause.
You can optionally pass this information directly into the update function as a string:</p>
@@ -634,15 +634,15 @@ You can optionally pass this information directly into the update function as a
<p>Or as an array:</p>
<code>$this->db->update('mytable', $data, array('id' => $id));</code>
-
+
<p>You may also use the <dfn>$this->db->set()</dfn> function described above when performing updates.</p>
-
+
<a name="delete">&nbsp;</a>
<h1>Deleting Data</h1>
-
+
<h2>$this->db->delete();</h2>
<p>Generates a delete SQL string and runs the query.</p>