我正在尝试根据日期(y-m-d)设置数据库中员工的状态。如果是两周前,并且他们设定了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));
}
}
}
}
答案 0 :(得分:0)
如果我没记错的话,你就不能使用INTERVAL的参数..用PDO做的一天(虽然我可能会记错)。
如果是这样,您将不得不使用intval()
或其他任何内容对其进行清理,并将其包含在原始SQL中。
e.g。使用sprintf('%d')
进行清理以强制$memATF
为整数:
$newsql = sprintf('update csvdata set status =:newstatus where statuschangedate < NOW() - INTERVAL %d DAY AND username =:mem', $memATF);
答案 1 :(得分:0)
试试这个:
$newsql = "update csvdata set status =:newstatus where username =:mem and statuschangedate < DATE_SUB(NOW(), INTERVAL :atf DAYS)";
我会改变这一行:(因为这可能意味着$ memATF可能是NULL或字符串)
if ($memATF != 0 || $memATF != "0")
为:
$memATF = intval($memATF);
if ($memATF >0)
这将确保$ memATF必须是一个整数,如果整数大于zeo,代码将继续运行。
答案 2 :(得分:-1)
嘿伙计们我修理了它是因为:$tsql="UPDATE csvdata SET customernotes=:notes =:date WHERE username=:tusername";
注意...:notes =:date....
所以我刚拿出=:date
并且它现在完美无缺:)