Skip to content

Commit

Permalink
Updated Query Build custom string option for where to remove make it …
Browse files Browse the repository at this point in the history
…clear the values do not get escaped.
  • Loading branch information
lonnieezell committed Jun 30, 2021
1 parent 6d752f4 commit 5564f9d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions user_guide_src/source/database/queries.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Regular Queries

To submit a query, use the **query** function::

$db = db_connect();
$db->query('YOUR QUERY HERE');

The ``query()`` function returns a database result **object** when "read"
Expand Down
16 changes: 11 additions & 5 deletions user_guide_src/source/database/query_builder.rst
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,10 @@ This function enables you to set **WHERE** clauses using one of four
methods:

.. note:: All values passed to this function are escaped automatically,
producing safer queries.
producing safer queries, except when using a custom string.

.. note:: ``$builder->where()`` accepts an optional third parameter. If you set it to
``false``, CodeIgniter will not try to protect your field or table names.

#. **Simple key/value method:**

Expand Down Expand Up @@ -295,15 +298,18 @@ methods:
#. **Custom string:**
You can write your own clauses manually::


$where = "name='Joe' AND status='boss' OR status='active'";
$builder->where($where);

``$builder->where()`` accepts an optional third parameter. If you set it to
``false``, CodeIgniter will not try to protect your field or table names.
If you are using user-supplied data within the string, you MUST escape the
data manually. Failure to do so could result in SQL injections.
::

::
$name = $builder->db->escape('Joe');
$where = "name={$name} AND status='boss' OR status='active'";
$builder->where($where);

$builder->where('MATCH (field) AGAINST ("value")', null, false);

#. **Subqueries:**
You can use an anonymous function to create a subquery.
Expand Down

0 comments on commit 5564f9d

Please sign in to comment.