我必须执行类似于以下的查询:
<?php
//....connect to database
$old = "a,b,c,d";
$new = "e,f,g,h";
$insert = "UPDATE TABLE SET FIELD = CONCAT(" . $old . ", " . $new . ") WHERE something = 'something';
mysql_query($insert);
?>
基本上,我想在当前数据库条目后附加包含逗号的"new"字符串。但是由于 CONCAT 函数使用逗号,我遇到了麻烦。
有没有人有任何提示来完成此操作?
改变这一行
$insert = "UPDATE TABLE SET FIELD = CONCAT(" . $old . ", " . $new . ") WHERE something = 'something'";
对此
$insert = "UPDATE TABLE SET FIELD = CONCAT('$old', '$new') WHERE something = 'something'";
编辑:
如果您想在要连接的 $old
和 $new
字符串之间使用逗号,请使用 CONCAT_WS ( http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_concat-ws )
像这样:
$insert = "UPDATE TABLE SET FIELD = CONCAT_WS(',', '$old', '$new') WHERE something = 'something'";