我有一行,其中 url
列具有以下值:
http://example.com/a~~1234567890-=!@#$%^&*()_+[\"test\"]
当我执行以下查询时:
SELECT * FROM `mytable` WHERE `url` = 'http://example.com/a~~1234567890-=!@#$%^&*()_+[\"test\"]'
MySQL 说记录不存在。
最佳答案
您需要转义两个\"中的\,因为\"是一个转义序列:只有引号 "会保留在执行的查询中。
\" [is an escape sequence turned into a] double quote (“"”) character
\\ [is an escape sequence turned into a] backslash (“\”) character
http://dev.mysql.com/doc/refman/5.7/en/string-literals.html
所以
SELECT * FROM `mytable` WHERE `url` = 'http://example.com/a~~1234567890-=!@#$%^&*()_+[\\"test\\"]'
关于php - 在 MySQL 中选择一些特殊字符时的奇怪行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39741804/