PDO查询无法更新但返回成功

时间:2014-08-28 13:22:18

标签: php sql postgresql pdo sql-update

根据我下面的代码,我试图创建一个如下所示的SQL查询:

update support_term set units_dk=$value['machines'] where support_acct='$key' and term_id=$term;

这是我用来尝试进行sql更新的PDO语句:

 foreach($data as $key => $value) {
            $setAccounts = $conn->prepare('UPDATE '.STERM_T.' SET units_dk=? WHERE support_acct=? and term_id=?');
            $setAccounts->setFetchMode(PDO::FETCH_ASSOC);
            $setAccounts->bindParam(1, $value['machines']);
            $setAccounts->bindParam(2, $key);
            $setAccounts->bindParam(3, $term);
            echo 'Machines:' . $value['machines'] . '. Key:' . $key . '. Term:' . $term . PHP_EOL;
            if(!is_null($key) || $key != '') {
                $setAccounts->execute();
            }
        }

更新作为成功返回但是我没有看到相关记录正在更新。看看我在这里回应的是显示的内容:

Machines:38. Key:sc-ai. Term:1145

基于此,我构建了一个SQL更新:

update support_term set units_dk=38 where support_acct='sc-ai' and term_id=1145;
select term_id,support_acct,units_dk from support_term where support_acct='sc-ai' and term_id=1145;

结果:

results

因此您可以看到更新有效。那么为什么在通过PDO完成时不更新任何记录?

0 个答案:

没有答案
相关问题