Search code examples
phpmysqlmysql-real-escape-stringapostrophe

apostrophe like and equal clause not working


I have one table named tags and it contain entry which is as below.

 ID   Name       Created Date
 10 limit\'s 2013-06-27 05:18:35

Now i want to search for limit's using query but could not search record.

For what i have tried.

'SELECT id FROM tags AS Tag WHERE name = "%'. urlencode($adTag) .'%" LIMIT 0,1'

'SELECT id FROM tags AS Tag WHERE name LIKE "%'. htmlspecialchars($adTag) .'%" LIMIT 0,1'

'SELECT * FROM tags AS Tag WHERE name LIKE "%'. $adTag .'%" OR REPLACE(name,'''','') LIKE "%'. $adTag .'%"'

'SELECT id FROM tags AS Tag WHERE name LIKE "%'. mysql_real_escape_string( stripslashes($adTag)) .'%" LIMIT 0,1'

'SELECT id FROM tags AS Tag WHERE name LIKE "%'. mysql_real_escape_string($adTag) .'%" LIMIT 0,1'

Where $adTag is coming dynamically and its value is limit's. Above are tried but none of that worked.

Let me know what i am doing wrong so i can correct mysql.

Thanks.


Solution

  • Well after so many googleing work done i finally get this working.

    below is the solution for me.

    SELECT *
    FROM tags
    WHERE `name` = 'limit\\''s'
    LIMIT 0 , 30
    

    Its worked like charm. Hope this will help in future for other geeks.