我有这个代码,我将在最近几个小时内对其进行测试,但无法理解为什么TodayAttendanceCount
不会返回0。
$sqlCheckLoginEntryCount = "SELECT Count(*) TodayAttendanceCount FROM AttendanceMachineLogin
WHERE Date(RecordAddDateTime) = :RecordAddDateTime
AND TimeTrackId = :TimeTrackId";
$statementEntryCount = $connPDO->prepare($sqlCheckLoginEntryCount);
$queryParams = array(
':TimeTrackId' => $TimeTrackId,
':RecordAddDateTime' => $RecordAddDateTime
);
$statementEntryCount->execute($queryParams);
$queryData = $statementEntryCount->fetch();
echo '\n ';
//var_dump($queryData);
echo "\n Attendance Count". $queryData['TodayAttendanceCount'] ." ;";
我已经在MySqlWorkbench中执行了相同的查询,该查询工作正常并且有数据,并且从数据库端来看也很好。
答案 0 :(得分:0)
在:
处删除$queryParams
部分。不需要代码将如下所示。
$queryParams = array(
'TimeTrackId' => $TimeTrackId,
'RecordAddDateTime' => $RecordAddDateTime
);
答案 1 :(得分:-1)
尝试一下:
$sqlCheckLoginEntryCount = "SELECT Count(*) As TodayAttendanceCount FROM AttendanceMachineLogin
WHERE Date(RecordAddDateTime) = ':RecordAddDateTime'
AND TimeTrackId = :TimeTrackId";
$statementEntryCount = $connPDO->prepare($sqlCheckLoginEntryCount);
$queryParams = array(
'TimeTrackId' => $TimeTrackId,
'RecordAddDateTime' => $RecordAddDateTime
);
$statementEntryCount->execute($queryParams);
$queryData = $statementEntryCount->fetch(PDO::FETCH_ASSOC);
echo '\n ';
//var_dump($queryData);
echo "\n Attendance Count ". $queryData['TodayAttendanceCount'];
希望我进一步推动了你。