查询无法在脚本上检索结果,但在phpmyadmin页面上可以正常工作

时间:2019-01-28 11:00:48

标签: mysql sql

我有一个与phpmyadmin sql一起正常工作的查询,但不适用于php脚本,它可以工作但什么也没找回

SELECT * 
from individuals 
where STR_TO_DATE(birthdate, '%d/%m/%Y') >= STR_TO_DATE('01/01/1984', '%d/%m/%Y') 
  && STR_TO_DATE(birthdate, '%d/%m/%Y') <= STR_TO_DATE('01/01/2002','%d/%m/%Y') 
  && (address LIKE '%جدة%' 
    || address LIKE '%جده%' 
    || address LIKE '%الطائف%' 
    || address LIKE '%مكة%' 
    || address LIKE '%مكه%'
    || address LIKE '%رابغ%') 
ORDER BY`individuals`.`birthdate` ASC

连接和一切都很好,它可以在没有条件的情况下正常工作

1 个答案:

答案 0 :(得分:1)

在SQL中,

||是带引号,而不是OR!并且也将&&替换为AND

更改为

SELECT * 
from individuals 
where STR_TO_DATE(birthdate, '%d/%m/%Y') >= STR_TO_DATE('01/01/1984', '%d/%m/%Y') 
  AND STR_TO_DATE(birthdate, '%d/%m/%Y') <= STR_TO_DATE('01/01/2002','%d/%m/%Y') 
  AND (address LIKE '%جدة%' 
    OR address LIKE '%جده%' 
    OR address LIKE '%الطائف%' 
    OR address LIKE '%مكة%' 
    OR address LIKE '%مكه%'
    OR address LIKE '%رابغ%') 
ORDER BY`individuals`.`birthdate` ASC

顺便说一句:将生日的数据类型更改为date