SQLSTATE [42S22]:找不到列

时间:2015-07-23 11:16:52

标签: php mysql phalcon

我想更新记录:

<?php

use Phalcon\Mvc\Model;
use Phalcon\Mvc\Model\Query;

class Client extends Model {
    function modifierClient($tab) {

        $setColumns = "";
        $separateur = "";

        foreach ($tab as $k => $v){
          if ($k == 'clt_id')
            continue;
          $setColumns .= $separateur . 'c.' . $k . " = '" . $v . "'";
          $separateur = ",";
        }

        $sSQL = "UPDATE client c SET $setColumns WHERE c.clt_id = '".$tab['clt_id']."'";

        $query = new Query($sSQL, $this->getDI());
        $ret = $query->execute();

    }
}

$tab数组包含以下索引:

Array
(
    [clt_id] => 7
    [clt_cin_pass] => aaaaa
    [clt_nom] => aaaaaaaaa
    [clt_prenom] => aaaaaaaaaa
    [clt_tel] => aaaaaaaa
    [clt_adresse] => aaaaaaaa
    [clt_comment] => aaaaaaaaaayy
)

在运行时我收到此错误:Exception: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'client.clt_id' in 'field list'

那有什么不对?

更新

这是phpMyAdmin的表结构:

enter image description here

2 个答案:

答案 0 :(得分:0)

试试这种方式

$sSQL = "UPDATE client c SET ".$setColumns." WHERE clt_id = '".$tab['clt_id']."'";

答案 1 :(得分:0)

我找到了解决方案:我在SET子句和WHERE中的每一列都加上了表名!