试图搬到 PDO 并度过一段美好的时光。这是我的代码,它工作不正常:
$db = new PDO('mysql:host=localhost;dbname=pp_production;charset=utf8', 'mr', 'jones');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$report_date = "DATE(time_track.punch_in) = CURRENT_DATE ORDER BY time_track.punch_in DESC";
$query_clock_history = $db->prepare("SELECT time_track.id, time_track.job_id, first_name, activity, time_track.comments, time_track.punch_in, time_track.punch_out, TIMESTAMPDIFF(MINUTE, time_track.punch_in, time_track.punch_out) AS time_spent, customers.customer_name, typesetting.description, typesetting.job_ticket FROM typesetting
JOIN time_track ON typesetting.id = time_track.job_id
JOIN employees ON employees.id = time_track.employee_id
JOIN activities ON activities.id = time_track.activity_id
JOIN customers ON customers.id = typesetting.customers_id
WHERE :report_date");
$query_clock_history->bindValue(':report_date', $report_date, PDO::PARAM_STR);
$query_clock_history->execute();
因此,这不会返回任何结果。如果我将 :report_date 替换为 $report_date 变量的实际内容,它就可以工作。一段时间以来,我一直在努力解决这个问题,但无法让它发挥作用。非常感谢任何帮助。这是在 MAMP 上运行的,如果有什么不同的话。
尝试了一些不起作用的东西
$report_date = "CURRENT_DATE";
...
WHERE DATE(time_track.punch_in) = :report_date ORDER BY time_track.punch_in DESC");
依然没有。这似乎是一个简单的例子,但我不知道为什么它不起作用。