1

这是我遇到的一个奇怪问题。我正在尝试通过用逗号连接旧值和新值来用新值更新数据库表中的值。所以基本上我现在的价值是:你好,我正在将它更新为 World,我希望新的价值是 Hello,world,但我无法做到这一点。CONCAT 和 CONCAT_WS 都通过您的语法无效的错误来运行。

表名是字段。我希望更新的列是值,要连接的新值是 $newval。这是我的查询。

$sql="update fields set values=CONCAT_WS(',',values, '$newval') where name='fundType'";

我收到此错误:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'values=CONCAT_WS(',',values, 'Buyout') where name='fundType'' at line 1

任何帮助将不胜感激。艾哈迈尔 A.

4

1 回答 1

3

values是mysql的一个关键字。使用反引号``将其标记为字段名称:

$sql="update fields set `values`=CONCAT_WS(',',`values`, '$newval') where name='fundType'";
于 2013-08-08T09:39:02.013 回答