summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--system/database/DB_active_rec.php57
-rw-r--r--user_guide/database/active_record.html18
2 files changed, 61 insertions, 14 deletions
diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php
index cea9bddc5..0a4327b42 100644
--- a/system/database/DB_active_rec.php
+++ b/system/database/DB_active_rec.php
@@ -276,7 +276,7 @@ class CI_DB_active_record extends CI_DB_driver {
* @return object
*/
- function where_in_or($key = NULL, $values = NULL)
+ function or_where_in($key = NULL, $values = NULL)
{
return $this->_where_in($key, $values, FALSE, 'or');
}
@@ -314,7 +314,7 @@ class CI_DB_active_record extends CI_DB_driver {
* @return object
*/
- function where_not_in_or($key = NULL, $values = NULL)
+ function or_where_not_in($key = NULL, $values = NULL)
{
return $this->_where_in($key, $values, FALSE, 'or');
}
@@ -372,7 +372,25 @@ class CI_DB_active_record extends CI_DB_driver {
{
return $this->_like($field, $match, 'AND ', $side);
}
-
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Not Like
+ *
+ * Generates a NOT LIKE portion of the query. Separates
+ * multiple calls with AND
+ *
+ * @access public
+ * @param mixed
+ * @param mixed
+ * @return object
+ */
+ function not_like($field, $match = '', $side = 'both')
+ {
+ return $this->_like($field, $match, 'AND ', $side, ' NOT');
+ }
+
// --------------------------------------------------------------------
/**
@@ -394,6 +412,24 @@ class CI_DB_active_record extends CI_DB_driver {
// --------------------------------------------------------------------
/**
+ * OR Not Like
+ *
+ * Generates a NOT LIKE portion of the query. Separates
+ * multiple calls with OR
+ *
+ * @access public
+ * @param mixed
+ * @param mixed
+ * @return object
+ */
+ function or_not_like($field, $match = '', $side = 'both')
+ {
+ return $this->_like($field, $match, 'OR ', $side, 'NOT ');
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* orlike() is an alias of or_like()
* this function is here for backwards compatibility, as
* orlike() has been deprecated
@@ -416,7 +452,7 @@ class CI_DB_active_record extends CI_DB_driver {
* @param string
* @return object
*/
- function _like($field, $match = '', $type = 'AND ', $side = 'both')
+ function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '')
{
if ( ! is_array($field))
{
@@ -424,22 +460,23 @@ class CI_DB_active_record extends CI_DB_driver {
}
foreach ($field as $k => $v)
- {
+ {
+
$prefix = (count($this->ar_like) == 0) ? '' : $type;
-
+
$v = $this->escape_str($v);
-
+
if ($side == 'before')
{
- $this->ar_like[] = $prefix." $k LIKE '%{$v}'";
+ $this->ar_like[] = $prefix." $k $not LIKE '%{$v}'";
}
elseif ($side == 'after')
{
- $this->ar_like[] = $prefix." $k LIKE '{$v}%'";
+ $this->ar_like[] = $prefix." $k $not LIKE '{$v}%'";
}
else
{
- $this->ar_like[] = $prefix." $k LIKE '%{$v}%'";
+ $this->ar_like[] = $prefix." $k $not LIKE '%{$v}%'";
}
}
return $this;
diff --git a/user_guide/database/active_record.html b/user_guide/database/active_record.html
index cf8ad469f..d938b5dff 100644
--- a/user_guide/database/active_record.html
+++ b/user_guide/database/active_record.html
@@ -18,7 +18,6 @@
<meta name='robots' content='all' />
<meta name='author' content='Rick Ellis' />
<meta name='description' content='CodeIgniter User Guide' />
-
</head>
<body>
@@ -274,7 +273,7 @@ $this->db->or_where('id >', $id);
$this->db->where_in('username', $names);<br />
// Produces: AND WHERE username IN ('Frank', 'Todd', 'James')</code></p>
-<h2>$this->db->where_in_or();</h2>
+<h2>$this->db->or_where_in();</h2>
<p>Generates a WHERE field IN ('item', 'item') SQL query joined with OR if appropriate</p>
<p><code>
$names = array('Frank', 'Todd', 'James');<br />
@@ -288,7 +287,7 @@ $this->db->or_where('id >', $id);
$this->db->where_not_in('username', $names);<br />
// Produces: AND WHERE username NOT IN ('Frank', 'Todd', 'James')</code></p>
-<h2>$this->db->where_not_in_or();</h2>
+<h2>$this->db->or_where_not_in();</h2>
<p>Generates a WHERE field NOT IN ('item', 'item') SQL query joined with OR if appropriate</p>
<p><code>
$names = array('Frank', 'Todd', 'James');<br />
@@ -338,7 +337,7 @@ $this->db->or_where('id >', $id);
<p>This function is identical to the one above, except that multiple instances are joined by OR:</p>
<code>
-$this->db->like('title', $match);<br />
+$this->db->like('title', 'match');<br />
$this->db->or_like('body', $match);
<br />
<br />// WHERE title LIKE '%match%' OR body LIKE '%match%'</code>
@@ -347,6 +346,17 @@ $this->db->or_like('body', $match);
<p class="important">Note: or_like() was formerly known as orlike(), which has been deprecated.</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>
+<code> $this-&gt;db-&gt;not_like('title', 'match');<br />
+<br />
+// WHERE title NOT LIKE '%match%</code>
+<h2>$this-&gt;db-&gt;or_not_like();</h2>
+<p>This function is identical to <strong>not_like()</strong>, except that multiple instances are joined by OR:</p>
+<code> $this-&gt;db-&gt;like('title', 'match');<br />
+$this-&gt;db-&gt;or_not_like('body', 'match'); <br />
+<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>