-1

我正在尝试根据日期(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));


            }


        }
        }

    }
4

3 回答 3

0

如果我没记错的话,你不能在 PDO 中使用 INTERVAL .. DAY 的参数(不过我可能记错了)。

如果是这样,您将不得不使用intval()或其他任何方式对其进行清理,并将其包含在原始 SQL 中。

sprintf('%d')例如,使用强制$memATF整数进行消毒:

$newsql = sprintf('update csvdata set status =:newstatus where statuschangedate < NOW() - INTERVAL %d DAY AND username =:mem', $memATF);
于 2013-04-16T21:07:26.560 回答
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,代码将继续运行。

于 2013-04-16T21:13:55.233 回答
-1

嘿伙计们,我修好了它是因为:$tsql="UPDATE csvdata SET customernotes=:notes =:date WHERE username=:tusername";请注意,...:notes =:date....所以我刚刚取出了=:date它,它现在可以正常工作了 :)

于 2013-04-16T21:39:46.747 回答