Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Query Build custom string option for where to remove make it clear the values do not get escaped. #4892

Merged
merged 1 commit into from
Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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