Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6475987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:46:12+00:00 2026-05-25T06:46:12+00:00

When I have a SQL query built that contains parentheses in one of the

  • 0

When I have a SQL query built that contains parentheses in one of the search values, I do not get the result that I am expecting. However, if I run the query on my database directly I have the expected result returned.

Also, if my search does not contain parentheses it will properly return the expected result.

CodeIgniter model function:

function get_submodels($params)
{
 $sql = "SELECT DISTINCT(`a`.`submodel`), `a`.`model_id` FROM `models` AS `a`"
 . "LEFT JOIN `manufacturers` AS `b` ON `a`.`manufacturer` = `b`.`manufacturer_id`"
 . "WHERE `a`.`year` = ? AND `b`.`manufacturer` = ? AND `a`.`model` = ?"
 . "ORDER BY `a`.`submodel` ASC;";

 $query = $this->db->query($sql, $params);

 return $query->result();
}

An example of a working query:

"... WHERE `a`.`year` = '2007' AND `b`.`manufacturer` = 'CHEVROLET' AND `a`.`model` = 'MONTE CARLO'"

An example of a non-working query:

"... WHERE `a`.`year` = '2007' AND `b`.`manufacturer` = 'MERCEDES BENZ' AND `a`.`model` = 'CLK350 (W209)'"

I have used $this->db->last_query() and the query is formatted properly. Even copying the last query that has no results and running it against the database directly will get the result expected.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:46:13+00:00Added an answer on May 25, 2026 at 6:46 am

    Despite running $this->db->last_query() and seeing the query as being proper, I decided to enable profiling on the page. My results show that the parenthesis where being encoded into HTML entities.

    Therefore, the query was being formed as this:

    "... WHERE `a`.`year` = '2007' AND `b`.`manufacturer` = 'MERCEDES BENZ' AND `a`.`model` = 'CLK350 (W209)'"
    

    Instead of this:

    "... WHERE `a`.`year` = '2007' AND `b`.`manufacturer` = 'MERCEDES BENZ' AND `a`.`model` = 'CLK350 (W209)'"
    

    I resolved this by modifying the insert query to use htmlentities for these columns and updated all existing records. While I knew the Codeigniter would escape values I was not aware that it would encode them as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a sql query that runs super fast, around one second, when not
I have built a T-SQL query like this: DECLARE @search nvarchar(1000) = 'FORMSOF(INFLECTIONAL,hills) AND
I have an SQL query that takes the following form: UPDATE foo SET flag=true
I have a SQL query that takes a very long time to run on
We have a SQL query that pulls a large number of fields from many
I have a sql query that performs the type of select I'm after: select
I have a table that contains many rows of SQL commands that make up
I recently built a query in SQL that I can use to look at
I have the following table: I am trying to create an SQL query that
I have a query that needs to return results that are NOT matched in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.