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

  • Home
  • SEARCH
  • 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 7550619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:15:33+00:00 2026-05-30T10:15:33+00:00

I am trying to insert a mysql query itself into a table field(Executing a

  • 0

I am trying to insert a mysql query itself into a table field(Executing a series of queries when certain conditions met), but whenever there is any special characters in query, it is converted in to its corresponding entities.

For example, if Iam inserting this query to table, the quote will become ” '” , > to > and space to &# . Is there any way to insert the query as it is and display in correct form .

    "select
      case item_id
      when 206 then '1 Column'
      when 255 then '2 Columns'
      end as split,
      # case oi.product_id
      #   when 24 then 'XXXX'
      #   when 28 then 'CCCC'
      #   when 30 then 'EEEE'
      #   else 'Something Else'
      # end as product,
     case oi.price_id
       when 72 then 'UYT - Single Pay'
       when 73 then 'UYT - Single Pay'
       when 74 then 'UYT - Single Pay'
     else 'Upsell'
     end as product,
     count(distinct(al.cust_id)) as the_count
     from logtable al
     where item_id in (206,255) and
        activity_dts > '2012-01-31 19:15:00' and
        o.order_is_refunded = 0 and
        t.response_code = 1 and
        t.response_reasontext not like '%testmode%'
        group by   1,2;"

Please give me suggestions or Am I missing any thing here. The charset used by my CI installation is UTF-8.

  • 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-30T10:15:35+00:00Added an answer on May 30, 2026 at 10:15 am

    There shouldn’t be any problem with inserting your string, as it IS a string, and the database library doesn’t make any character encoding by itself, afaik. What encoding are the database and the tables? (the connection should be UTF-8, as per default settings)

    Since you’re using the framework, you can use its methods (and not mysql_real_escape_string() or, god, addslashes()!! like suggested in other answers).This should work:

    $string_query = "select
          case item_id
          when 206 then '1 Column'
          when 255 then '2 Columns'....";
    $sql = "INSERT INTO table(column) VALUES (?)";
    $this->db->query($sql, array($string_query));
    

    The query bindings automatically escapes FOR SQL, so for that you’re safe (you could have used ActiveRecord with the same result). I don’t know what couldn’t be working in this, surely NO FUNCTIONS encodes html.

    Maybe you’re doing the encoding somewhere else: are you sure you’re not calling xss_clean(), htmlspecialchars()/htmlentities(), or you have XSS protection enabled, or you pass TRUE as second paramenter of $this->input-> ?

    If all the above for some reason – for wich you didn’t provide enought information – fails, you can alwasy encode everything:

    $string_query = base64_encode("select.....");
    // HERE YOU MAKE THE INSERT QUERY
    

    and when you retrieve it, you base64_decode() the string. But the ideal solution is not this, it should work without flaws anyway.

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

Sidebar

Related Questions

I am trying to insert a string in MySQL table. But the following is
Im trying to insert data into a table in MySQL. I found/modified some code
I am trying to insert a future date into a MySQL table from PHP.
Into a MYSQL query, I am trying to insert a WHERE clause (the one
I'm trying to insert a file path into an empty MySQL table with PHP
I am trying to insert emails into a MYSQL table, and I am getting
im trying to insert this query with mysql_query INSERT INTO um_group_rights (`um_group_id`,`cms_usecase_id`,`um_right_id`) VALUES (2,1,1)
I am trying to insert a very long text string into a MySQL Blob
I received a MySQL data dump and am trying to insert the data into
I am trying to INSERT INTO a table using the input from another table.

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.