PDO提取返回零

时间:2018-08-15 06:07:14

标签: php pdo

我有这个代码,我将在最近几个小时内对其进行测试,但无法理解为什么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中执行了相同的查询,该查询工作正常并且有数据,并且从数据库端来看也很好。

2 个答案:

答案 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'];

希望我进一步推动了你。