Mysqli字符串比较由于引号中的反向而失败

时间:2015-08-18 06:28:22

标签: php mysql

我有这样的查询:

SELECT p.PRO_Id 
FROM projects p, developer d 
WHERE p.PRO_Name = 'Navin Enclave\'s' 
  AND d.DEV_Name = 'Navin\'s group of Companies' 
  AND p.DEV_Id=d.DEV_Id 
LIMIT 1

这是为了获取项目名称' Navin Enclave' 以及开发人员。

mysql db值存储为' Navin Enclave' 正确转义引号。

但我无法得到预期的结果。

我的mysqli包装类是:https://github.com/joshcam/PHP-MySQLi-Database-Class

1 个答案:

答案 0 :(得分:1)

SELECT p.PRO_Id

FROM projects p,developer d

在哪里p.PRO_Name LIKE'%Navin Enclave \\'s%''

AND d.DEV_Name LIKE'%Navin \\'s%'//将反过来获取Navin的公司组

AND p.DEV_Id = d.DEV_Id 限制1

参考:How to search for slash (\) in MySQL? and why escaping (\) not required for where (=) but for Like is required?