查询=未知系统变量' c3'

时间:2014-12-03 10:40:59

标签: php mysqli

尝试在查询中同时使用REPLACESET,但没有成功!

错误讯息:

Unknown system variable 'c3'

我做错了什么?

PHP

 $query = "SET NEW.c3 = CONCAT(OLD.c3, NEW.:c3);
           REPLACE INTO table(
                c1,
                c2,
                c3)
           VALUES(
                :c1,
                :c2,
                :c3)";
$query_params = array(
                ':c1' => $c1,
                ':c2' => $c2,
                ':c3' => $c3); 

1 个答案:

答案 0 :(得分:0)

我的猜测是你要插入一个新行或更新现有的行(如果它已经存在于表中)。如果是这种情况,那么正确的查询是:

INSERT INTO table(c1, c2, c3) VALUES
    (:c1, :c2, :c3)
ON DUPLICATE KEY UPDATE
    c3 = CONCAT(c3, :c3);

或者,如果您想一次插入/更新多行:

INSERT INTO table(c1, c2, c3) VALUES
    (:c1, :c2, :c3),
    (:d1, :d2, :d3),
    (:e1, :e2, :e3)
ON DUPLICATE KEY UPDATE
    c3 = CONCAT(c3, VALUES(c3));