Match '%' sign when searching in MySQL database

后端 未结 5 1121
礼貌的吻别
礼貌的吻别 2020-12-19 09:49

I would like to match this \'wildcard %\' in MySQL.
I tried using escape \\% and it is not working.

5条回答
  •  时光取名叫无心
    2020-12-19 10:24

    You need to escape the \ in PHP string as well, otherwise PHP would think that you are actually escaping the %, thus sending literal % to the sql query, so I think this should work:

    mysql_query("select * from bla where bli like '\\%somewords\\%'");
    

提交回复
热议问题