我正在尝试根据日期(ymd)在数据库中设置员工的状态。如果是两周前,他们设置了 1 周的时间做某事,那么状态应该会改变。我是这样做的:
$newsql = "update csvdata set status =:newstatus where statuschangedate < NOW() - INTERVAL :atf DAY AND username =:mem";
$newgetcsvuser = $DBH->prepare($newsql);
$newgetcsvuser->execute(array(':newstatus' => $newStatus, ':atf' => $memATF, ':mem' => $csvusername));
由于某种原因,当我运行它时它不起作用。困惑为什么不呢?
编辑:
所以如果我echo "working";
在最后添加,我的页面上会说错误,内部错误。
编辑:
这是整个事情......
$date = date("Y-m-d");
$newStatus = "Non-Active - Driver Chose Non-Compliance";
$sql = "SELECT username,ATF FROM members";
$getcsvuser = $DBH->prepare($sql);
$getcsvuser->execute();
while($row = $getcsvuser->fetch(PDO::FETCH_ASSOC)){
$memusername = $row['username'];
$memATF = $row['ATF'];
if ($memATF != 0 || $memATF != "0")
{
$tsql = "SELECT username,status,memberview ,statuschangedate,customernotes FROM csvdata WHERE memberview =:user";
$tgetcsvuser = $DBH->prepare($tsql);
$tgetcsvuser->execute(array(':user' => $memusername));
while($trow = $tgetcsvuser->fetch(PDO::FETCH_ASSOC)){
$csvstatus = $trow['status'];
$csvusername = $trow['username'];
$csvdate = $trow['statuschangedate'];
if($csvstatus == "Open" || $csvstatus == "Enrolled - Policyholder Follow-Up Required" || $csvstatus == "Enrolled - Employee Follow-Up Required" || $csvstatus == "Non-Active - Insurance Cancelled" || $csvstatus == "Non-Active, Unable to Monitor - Incidental Business use Exclusion" || $csvstatus == "Non-Active - Employee Not Covered Under Listed Policy" || $csvstatus == "Non-Active - PolicyHolder Cancelled Additional Interest")
{
$notes = $trow['customernotes'];
$notes = $csvstatus . " - ATF. " . $notes;
$tsql="UPDATE csvdata SET customernotes=:notes =:date WHERE username=:tusername";
$tsth=$DBH->prepare($tsql);
$tsth->execute(array(':notes' => $notes,':tusername' => $csvusername));
$newsql = "update csvdata set status =:newstatus where username =:mem and statuschangedate < DATE_SUB(NOW(), INTERVAL :atf DAYS)";
//$newsql = sprintf('update csvdata set status =:newstatus where statuschangedate < NOW() - INTERVAL %d DAY AND username =:mem', $memATF);
$newgetcsvuser = $DBH->prepare($newsql);
$newgetcsvuser->execute(array(':newstatus' => $newStatus, ':atf' => $memATF, ':mem' => $csvusername));
echo "working";
$ynewsql = "update csvdata set statuschangedate =:date where username =:mem";
$ynewgetcsvuser = $DBH->prepare($ynewsql);
$ynewgetcsvuser->execute(array(':date' => $date, ':mem' => $csvusername));
}
}
}
}