我只是想知道为什么此查询在浏览器中的PHP中什么也不返回,而在MySQL Workbench中使用时却返回大量的项。
我通过回显这两个日期来获取日期,然后使用相同的日期并在MySQL Workbench中返回项目。
$_POST['startdate']
$_POST['enddate']
所以我不确定为什么它在查询中不起作用。没有出现PHP或MySQL错误/警告。
SELECT
mantis_category_table.name,
mantis_bug_history_table.bug_id,
FROM_UNIXTIME(mantis_bug_table.date_submitted, "%m-%d-%Y") AS DATE2,
FROM_UNIXTIME(min(mantis_bug_history_table.date_modified), "%m-%d-%Y") AS FirstOfdate_modified,
ROUND((min(mantis_bug_history_table.date_modified)- mantis_bug_table.date_submitted)/ 86400, 1) as day_difference
FROM (mantis_bug_table INNER JOIN mantis_bug_history_table
ON
mantis_bug_table.id = mantis_bug_history_table.bug_id)
INNER JOIN
mantis_category_table ON mantis_bug_table.category_id = mantis_category_table.id
WHERE
FROM_UNIXTIME(mantis_bug_table.date_submitted, "%m-%d-%Y")
BETWEEN '.$_POST['startdate'].' AND '.$_POST['enddate'].'
GROUP BY
mantis_category_table.name, mantis_bug_table.category_id, mantis_bug_table.date_submitted, mantis_bug_table.status, mantis_bug_history_table.bug_id, mantis_bug_history_table.field_name, mantis_bug_history_table.new_value
HAVING
(((mantis_bug_table.status)<>90) AND ((mantis_bug_history_table.field_name)="status") AND ((mantis_bug_history_table.new_value)="50"))
ORDER BY
mantis_category_table.name, mantis_bug_table.date_submitted'
问题似乎出在查询的这一部分。这在MySQL中无效吗?有更好的方法吗?
WHERE
FROM_UNIXTIME(mantis_bug_table.date_submitted, "%m-%d-%Y")
BETWEEN '.$_POST['startdate'].' AND '.$_POST['enddate'].'
谢谢。
按照OP的愿望:
像这样连接您的值:
BETWEEN "'.$_POST['startdate'].'" AND "'.$_POST['enddate'].'"
因为您缺少引号,因为我们正在处理字符串值。
日期可以包含连字符(和冒号),例如连字符(2015-01-05 22:00
将引起SQL错误)。
但是,我想指出,使用这种类型的查询对SQL注入开放。
使用mysqli
预处理语句,或与准备语句PDO,他们更安全。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句