summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--system/database/DB_query_builder.php5
-rw-r--r--tests/codeigniter/core/Output_test.php4
-rw-r--r--user_guide_src/source/database/query_builder.rst37
3 files changed, 25 insertions, 21 deletions
diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php
index 9bd535b0e..e77fba63d 100644
--- a/system/database/DB_query_builder.php
+++ b/system/database/DB_query_builder.php
@@ -903,11 +903,12 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
}
is_bool($escape) OR $escape = $this->_protect_identifiers;
- $prefix = (count($this->qb_where) === 0 && count($this->qb_cache_where) === 0)
- ? $this->_group_get_type('') : $this->_group_get_type($type);
foreach ($field as $k => $v)
{
+ $prefix = (count($this->qb_where) === 0 && count($this->qb_cache_where) === 0)
+ ? $this->_group_get_type('') : $this->_group_get_type($type);
+
$v = $this->escape_like_str($v);
if ($side === 'none')
diff --git a/tests/codeigniter/core/Output_test.php b/tests/codeigniter/core/Output_test.php
index 3384143e9..d8252403d 100644
--- a/tests/codeigniter/core/Output_test.php
+++ b/tests/codeigniter/core/Output_test.php
@@ -2,11 +2,13 @@
class Output_test extends CI_TestCase {
+ public $output;
+
public function set_up()
{
$this->ci_set_config('charset', 'UTF-8');
$output = $this->ci_core_class('output');
- $this->output = new $output();
+ $this->output = new $output();
}
// --------------------------------------------------------------------
diff --git a/user_guide_src/source/database/query_builder.rst b/user_guide_src/source/database/query_builder.rst
index 8fb906052..65609c1cb 100644
--- a/user_guide_src/source/database/query_builder.rst
+++ b/user_guide_src/source/database/query_builder.rst
@@ -345,23 +345,24 @@ if appropriate
$this->db->like()
=================
-This function enables you to generate **LIKE** clauses, useful for doing
+This method enables you to generate **LIKE** clauses, useful for doing
searches.
-.. note:: All values passed to this function are escaped automatically.
+.. note:: All values passed to this method are escaped automatically.
#. **Simple key/value method:**
::
- $this->db->like('title', 'match'); // Produces: WHERE title LIKE '%match%'
+ $this->db->like('title', 'match');
+ // Produces: WHERE `title` LIKE '%match%' ESCAPE '!'
- If you use multiple function calls they will be chained together with
+ If you use multiple method calls they will be chained together with
AND between them::
$this->db->like('title', 'match');
$this->db->like('body', 'match');
- // WHERE title LIKE '%match%' AND body LIKE '%match%
+ // WHERE `title` LIKE '%match%' ESCAPE '!' AND `body` LIKE '%match% ESCAPE '!'
If you want to control where the wildcard (%) is placed, you can use
an optional third argument. Your options are 'before', 'after' and
@@ -369,9 +370,9 @@ searches.
::
- $this->db->like('title', 'match', 'before'); // Produces: WHERE title LIKE '%match'
- $this->db->like('title', 'match', 'after'); // Produces: WHERE title LIKE 'match%'
- $this->db->like('title', 'match', 'both'); // Produces: WHERE title LIKE '%match%'
+ $this->db->like('title', 'match', 'before'); // Produces: WHERE `title` LIKE '%match' ESCAPE '!'
+ $this->db->like('title', 'match', 'after'); // Produces: WHERE `title` LIKE 'match%' ESCAPE '!'
+ $this->db->like('title', 'match', 'both'); // Produces: WHERE `title` LIKE '%match%' ESCAPE '!'
#. **Associative array method:**
@@ -379,37 +380,37 @@ searches.
$array = array('title' => $match, 'page1' => $match, 'page2' => $match);
$this->db->like($array);
- // WHERE title LIKE '%match%' AND page1 LIKE '%match%' AND page2 LIKE '%match%'
+ // WHERE `title` LIKE '%match%' ESCAPE '!' AND `page1` LIKE '%match%' ESCAPE '!' AND `page2` LIKE '%match%' ESCAPE '!'
$this->db->or_like()
====================
-This function is identical to the one above, except that multiple
+This method is identical to the one above, except that multiple
instances are joined by OR::
$this->db->like('title', 'match'); $this->db->or_like('body', $match);
- // WHERE title LIKE '%match%' OR body LIKE '%match%'
+ // WHERE `title` LIKE '%match%' ESCAPE '!' OR `body` LIKE '%match%' ESCAPE '!'
-.. note:: or_like() was formerly known as orlike(), which has been removed.
+.. note:: ``or_like()`` was formerly known as ``orlike()``, which has been removed.
$this->db->not_like()
=====================
-This function is identical to **like()**, except that it generates NOT
-LIKE statements::
+This method is identical to ``like()``, except that it generates
+NOT LIKE statements::
- $this->db->not_like('title', 'match'); // WHERE title NOT LIKE '%match%
+ $this->db->not_like('title', 'match'); // WHERE `title` NOT LIKE '%match% ESCAPE '!'
$this->db->or_not_like()
========================
-This function is identical to **not_like()**, except that multiple
+This method is identical to ``not_like()``, except that multiple
instances are joined by OR::
$this->db->like('title', 'match');
$this->db->or_not_like('body', 'match');
- // WHERE title LIKE '%match% OR body NOT LIKE '%match%'
+ // WHERE `title` LIKE '%match% OR `body` NOT LIKE '%match%' ESCAPE '!'
$this->db->group_by()
=====================
@@ -1054,4 +1055,4 @@ run the query::
$data = $this->db->get()->result_array();
// Would execute and return an array of results of the following query:
- // SELECT field1, field1 from mytable where field3 = 5;
+ // SELECT field1, field1 from mytable where field3 = 5; \ No newline at end of file