CodeIgniter Forums
special chars in mysql query - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Development & Programming (
+--- Thread: special chars in mysql query (/thread-44017.html)

special chars in mysql query - El Forum - 07-31-2011


I have a db in which I have rows with various data that contain characters like (),.:-_!
and they might contain ' and "
If I run a query through codeigniter using $this->db->query(...) I get these chars dropped out. I think it might be because of the escaping of queries. This means that I can't access these rows.
How can I preserve these characters in my query? (maybe except ' and " )

Best regards,

special chars in mysql query - El Forum - 07-31-2011

First I would suggest using active record instead of running the query directly. If you have to run the query directly though you can escape the special characters. Look for the bit on Escaping Queries, or you can use the data bindings, which is much better from a security standpoint.

special chars in mysql query - El Forum - 07-31-2011

Quotes are the only characters there that you need to worry about when included inside a string, unless you are using a search function (such as LIKE queries), in which you need to pay attention to characters such as % and _

If you use $this->db->query() alone, without the bindings array as the second parameter, your query will NOT be automatically escaped.

One step I think you might want to do is to typecast your strings/data - it's possible that the Database class is assuming your string is numeric or something else based on its content.

Pasting an example of a query you're using, as well as the an error and an example of the query CI is using (can be retrieved using $this->db->last_query()), we can be more specific about how to solve your problem.