homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

How to handle escape sequence in query
How to handle escape sequence in query

 12:34 pm on May 9, 2011 (gmt 0)


I have a problem. In my database there are a field, productType having data like Men's Jackets, Ladies' Gloves. When I try to run select query for productType, mysql returns with an error or empty result.

I have used mysql_real_escape_string() functions, but it works with the server version higher than 5.1.#*$!. The mysql version which I have on the serve is 5.0.9#*$!.

For version 5.1.#*$! following query is working perfect:

select * from products where productType = 'Men''s Jackets'

How can I write accurate query for mysql version 5.0.9#*$!.

Abid Shahzad



 4:29 pm on May 9, 2011 (gmt 0)

Go old school with it in a preg_replace.

$searchterm = preg_replace('/\'+/',"''",$searchterm);

$query = "select * from table where field='$searchterm'";

You may have to do a couple other things manually and encounter some conditional problems, but it works.


 4:44 pm on May 9, 2011 (gmt 0)

Thanks for reply.

This is working for MySql 5.1.x but not for 5.0.9.



 4:00 pm on May 10, 2011 (gmt 0)

Is your field type text when it should/could be varchar? I say that because on some versions and environments the quotes don't need to be escaped in text fields. You're not executing mysql_real_escape_string() in addition?

You can try it without the preg, but that has worked since version 4.-something.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved