php - 我总是在布尔值上调用成员函数 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> ' . $row['Name'] . '</div>';
echo '<div style="font-size:18px;" class="col-sm-12"><b>EMPLOYEE NAME:</b> ' . $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;
?>
解决方案
推荐阅读
- wordpress - 如何启用维度控制古腾堡?
- flutter - 为什么 Flutter Web 中的按钮没有边距?
- python - 在 post 方法的烧瓶应用程序中摆脱空输出
- redux - Redux 在另一个组件中访问状态
- vue.js - 弃用 - 该网站从网络请求子资源,由于其用户的特权网络位置,它只能访问该子资源
- swift - WKWebView 弹出窗口在 MacOS 应用程序中不起作用
- blockchain - 验证加密(BSC)地址属于某人
- javascript - onClick 多次触发 JS
- redis - 水平扩展物联网传感器收集器服务器
- python - 使用 os.system 的 python 和 xclip 有时会冻结