我有一个在 Mysql 中运行良好的查询
$日期
$date = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d"), date("Y")));
$date 和 $imdb_id 的 var_dump
string '2013-06-04' (length=10)
string '2244871' (length=7)
准备
SELECT * FROM show_episode, show_episode_airdate, show_network, shows
WHERE show_episode.imdb_id_show = :imdb_id
AND show_episode.episode_id = show_episode_airdate.episode_id
AND show_network.show_id = shows.id
AND shows.imdb_id = show_episode.imdb_id_show
AND show_episode_airdate.airdate >= :date
ORDER BY show_episode_airdate.airdate ASC LIMIT 3
这是PHP:
$checkunaired = $conn->prepare('SELECT * FROM show_episode, show_episode_airdate, show_network, shows WHERE show_episode.imdb_id_show = :imdb_id AND show_episode.episode_id = show_episode_airdate.episode_id AND show_network.show_id = shows.id AND shows.imdb_id = show_episode.imdb_id_show AND show_episode_airdate.airdate >= :date ORDER BY show_episode_airdate.airdate ASC LIMIT 3');
$checkunaired->execute(array(':imdb_id' => $imdb_id, ':date' => $date));
:date 是 $date,格式为“Ymd”,show_episode_airdate.airdate 是日期格式为“Ymd”的列(尽管我不确定 Mysql 是否知道它们是日期?)
当我在 phpmyadmin 中尝试使用“2013-06-04”而不是 :date 进行查询时,它返回了我想要的内容,但是当我在代码中使用它时似乎忽略了 date 参数?
有谁知道为什么?
编辑:
$unairedepisodessql = $conn->prepare('SELECT * FROM show_episode, show_episode_airdate, show_network WHERE show_episode.imdb_id_show = :imdb_id AND show_network.show_id = :show_id AND show_episode.episode_id = show_episode_airdate.episode_id AND show_episode_airdate.airdate >= :date LIMIT 3');
$erro = $unairedepisodessql->errorCode();
var_dump($erro);
返回空