【问题标题】:PHP MYSQL CONCAT with string containing comma in the startPHP MYSQL CONCAT,字符串开头包含逗号
【发布时间】:2013-08-09 23:09:09
【问题描述】:

这是我遇到的一个奇怪问题。我正在尝试通过用逗号连接新旧值来用新值更新数据库表中的值。所以基本上我现在的价值是: 你好,我正在将其更新为 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.

【问题讨论】:

    标签: php mysql concat


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2013-05-31
      • 1970-01-01
      • 1970-01-01
      • 2016-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-13
      • 1970-01-01
      相关资源
      最近更新 更多