Escape Chars

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

Escape Chars

Post by AliasBDI »

I have a very strange query to run for Search Friendly URLs. My search string is "mens" which was converted from the actual title "men's". I want to compare it with a record in the database which has the data set to "Men's". So I'm making the MySQL column to replace a few characters that I remove in the search string so that the compare is the same.

In other words, a record is Men's Ministry. I convert it to use in a URL making it "mens-ministry" and it is requested by another page and then queried back to the same database table (where it is in its original form and must be converted in order to accurately be compared).

So here is my query:

Code: Select all

$query_PgDetails = "SELECT * FROM ec_Pages WHERE levelID=1 AND REPLACE(REPLACE(REPLACE(LCASE(pg_Title),' ','-'),'\'',''),'\"','')='".$ec_Page."'";
It is not working and I believe it is due to the escape character next to the apostrophe. I think that PHP thinks it should escape. This is the echo of the query:

Code: Select all

SELECT * FROM ec_Pages WHERE levelID=1 AND REPLACE(REPLACE(REPLACE(LCASE(pg_Title),' ','-'),'\'',''),'"','')='mens-ministry'
Any ideas on how to resolve this?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Why can't you make a column in the table that houses the slug? Then you can do a 'WHERE slug = "mens-ministry"' and be done with it?
Post Reply