I am inserting some text from scraped web into my database. some of the fields in the string have unprintable/weird characters. For example,
if text is 'C__O__?__P__L__E__T__E', then the text in the database is stored only as 'C__O__'
I know about h(), strip_tags()… sanitize, … etc etc. But I do not want to sanitize this SQL. The activerecord logs the SQL correctly, and when run in phpMySQL, the query is executed correctly. something happens between the SQL query generation and it being executed.
Help is much appreciated.
Hmmmm.. using CGI escape, I found out that the character coming in the system is not what I expected it to be. It is not a question mark (%3F) but a question mark (%D5).
Eventually I gsubbed out the non-printable characters before saving.
Only after removing the invalid characters in my string, was I able to save the item properly. None of the other solutions worked, partially because the problem was not understood clearly upfront.