首页 > 解决方案 > 我总是在布尔值上调用成员函数 fetchAll()

问题描述

我总是fetchAll()在布尔输入上调用成员函数,我正在使用 Microsoft Access 我是 PDO 的新手,所以我不知道我是否做对了

我的错误:

致命错误
:未捕获的错误:调用 C:\xampp\htdocs\newtimein_timeout\filter.php:46 中布尔值的成员函数 fetch() 堆栈跟踪:#0 {main} 在
C:\xampp\htdocs\newtimein_timeout\中抛出
第 46 行的filter.php

<?php
    $dbName = 'C:\xampp\htdocs\newtimein_timeout\att2000.mdb';
    if (!file_exists($dbName)) {
    die("Could not find database file.");
    }
    $connect = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb)}; Server=localhost; 
    Port=3306; DBQ=$dbName; Uid=; Pwd=;");
    $output = ''; 
    $query = "select a.USERID, a.CHECKTIME, a.CHECKTYPE, b.Name, 
    b.Badgenumber,date_format(a.CHECKTIME, '%Y-%m-%d') as Date,
      (CASE
            WHEN date_format(c.CHECKTIME, '%h:%i:%s') IS NULL THEN '--:--:--'
            ELSE date_format(c.CHECKTIME, '%h:%i:%s')
        END) as start_time, 
        (CASE
            WHEN date_format(d.CHECKTIME, '%h:%i:%s') IS NULL THEN '--:--:--'
            ELSE date_format(d.CHECKTIME, '%h:%i:%s')
        END) as break_out,
        (CASE
            WHEN date_format(e.CHECKTIME, '%h:%i:%s') IS NULL THEN '--:--:--'
            ELSE date_format(e.CHECKTIME, '%h:%i:%s')
        END) as break_in,
        (CASE
            WHEN date_format(f.CHECKTIME, '%h:%i:%s') IS NULL THEN '--:--:--'
            ELSE date_format(f.CHECKTIME, '%h:%i:%s')
        END) as end_time 
      from checkinout a
      left join (select USERID, CHECKTIME from checkinout where CHECKTYPE='I') c
      ON a.USERID=c.USERID AND date_format(a.CHECKTIME, '%Y-%m-%d')=date_format(c.CHECKTIME, '%Y-%m-%d')
      left join (select USERID, CHECKTIME from checkinout where CHECKTYPE='0') d
      ON a.USERID=d.USERID AND date_format(a.CHECKTIME, '%Y-%m-%d')=date_format(d.CHECKTIME, '%Y-%m-%d')
      left join (select USERID, CHECKTIME from checkinout where CHECKTYPE='1') e
      ON a.USERID=e.USERID AND date_format(a.CHECKTIME, '%Y-%m-%d')=date_format(e.CHECKTIME, '%Y-%m-%d')
      left join (select USERID, CHECKTIME from checkinout where CHECKTYPE='O') f
      ON a.USERID=f.USERID AND date_format(a.CHECKTIME, '%Y-%m-%d')=date_format(f.CHECKTIME, '%Y-%m-%d')
      left join userinfo b 
      ON a.USERID=b.USERID
      WHERE a.USERID > 0";
          if(!empty($_POST["name"])){
            $query .= " AND b.Name like '%".$_POST["name"]."%' "; 
          } 
          if(!empty($_POST["from_date"]) && (!empty($_POST["to_date"])) ) {
            $query .= " AND date_format(a.CHECKTIME, '%Y-%m-%d') BETWEEN '".$_POST["from_date"]."' AND '".$_POST["to_date"]."' ";
          }
      $query .= " GROUP BY Date";

      $result = $connect->query($query);
      if ($row = $result->fetchAll()){
          echo '<div style="font-size:18px;" class="col-sm-12"><b>ID NUMBER:</b>&nbsp;' . $row['Name'] . '</div>';
          echo '<div style="font-size:18px;" class="col-sm-12"><b>EMPLOYEE NAME:</b>&nbsp;' . $row['Badgenumber'] . '</div>';
      }
      $output .= '  
                    <table class="table table-striped table-bordered">
                      <thead class="thead-dark">
                          <tr>
                              <th style="width:220px">Date</th>
                              <th>Time In</th>
                              <th>Break Out</th>
                              <th>Break In</th>
                              <th>Time Out</th>
                          </tr>
                      </thead>
      ';  

      if($result->fetchColumn() > 0)  
      {  
           while($row = $result->fetchAll())  
           {  
                $date=date_create($row['CHECKTIME']);
                $dDate = date_format($date,"M d, Y (D)");

                $output .= ' 
                        <tr>
                              <td>'. $dDate .'</td>
                              <td>'. $start_time .'</td>
                              <td>'. $break_out .'</td>
                              <td>'. $break_in .'</td>
                              <td>'. $end_time .'</td>
                        </tr>
                    ';
           }  
      }  
      else  
      {  
           $output .= '  
                <tr>  
                     <td colspan="5">No Data Found</td>  
                </tr>  
           ';  
      }  
      $output .= '</table>';  
      echo $output;  
?>

标签: phpms-accesspdo

解决方案


推荐阅读