更新单个单元MySQL PDO

时间:2016-08-30 16:42:16

标签: php mysql pdo sql-update

我正在尝试更新单个单元格但我不知道为什么但是每次尝试都会出现此错误:SQLSTATE[42S22]: Column not found: 1054 Unknown column 'partcipateInLolProject' in 'field list'

这是PHP代码:

    if(!isset($args['id'], $args['status'])){
      return $response->withStatus(400)->withHeader('Location', $this->router->pathFor('list-online-contacts-page'));
    }

    $id = $args["id"];
    $status = $args['status'];

    $prep = $this->db->prepare("UPDATE `onlineinscription` SET `partcipateInLolProject` = :status WHERE `id` = :id");

    $prep -> bindParam(':status', $status);
    $prep -> bindParam(':id', $id);
    $prep -> execute();

这些args先前由regex检查,并且都是1到5个数字长整数。当我在我的mysql提示符上运行完全相同的查询时,它就像一个魅力,这是测试查询:
UPDATE onlineinscription SET participateInLolProject = 1 WHERE id = 104
我在绑定它们之前检查了两个变量(status和id),它们是预期的。在正确的服务器/ DB上,MySQL凭据很好。 db早先创建如下:

    $db = $c->get('settings')['db'];
    $pdo = new PDO("mysql:host=" . $db['host'] . ";dbname=" . $db['dbname'], $db['user'], $db['pass'], array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
    return $pdo;

1 个答案:

答案 0 :(得分:1)

发现差异:

$prep = $this->db->prepare("[..snip..] `partcipateInLolProject` = :status WHERE `id` = :id");
                                            ^----

UPDATE onlineinscription SET participateInLolProject = 1 WHERE id = 104
                                 ^--- 

那么......下次再仔细阅读错误信息?