Hi Guys, another brain teaser.
This isn't the usual "but Apostrophes are breaking my Queries" as I know all about escaping and sanitising so I'll get right too it.
Many many things are stored in a db with names like "Assassin's" and "Babe's" which end up "Assassin\'s" and "Babe\'s", recovering is good but searching via text is... painful.
LIKE "%Babe\'s%" has no results, "%Babe\\'s" has no results, "%Babe\''s" has no results.
BUT if I go to the server directly then they will all produce results.
In other words, the SAME query totally unedited will work directly in the MySQL engine but sent via php's mysql api it produces no matched results.
Any ideas what could cause this? (I've checked 100 times the amount of slashes etc, is there a character set issue?"
Many many many many thanks in advance.
edit:
I think i better make myself more clear:
"SELECT title FROM games WHERE title LIKE "%assassin\\\'s%";
(Since SQL should escape the apostrophe and one of the slashes will turn into the slash that was stored, since we're looking for "Assassin\'s Creed" in this example)
edit2: Sow we've figured out this is caused by having escaped escapes in the actual db caused by poor sanitising. Currently I'm in the process of trying to cleanup the db and the input method.
edit3: It seems like magic quotes were on somehow... I swear that was turned off! However it wasn't just that. The DB wrapper which is in place for this site has a clean event and also a pre-clean which caused the issue. That has been fixed now and now I'm running a script to (hopefully) cleanse the db...