Home  >  Article  >  Backend Development  >  php追加数据到mysql

php追加数据到mysql

WBOY
WBOYOriginal
2016-06-23 14:26:27923browse

追加数据 php mysql

php追加数据到mysql

在mysql里的一个表user中有个name的字段
表中已经有一条记录
id字段值是1
name字段的值是"周"
我现在想追加"杰伦"两个字到这个字段中
也就是让这条记录的name字段的值从原来的"周"变成现在的"周杰伦"
请问要怎么操作呢?
如何写代码?
用代码
$sql="update user set name = name + '杰伦' where id='1'";
mysql_query($sql);
以后name字段的值却变成"0"了。


回复讨论(解决方案)

晕死
原来是这样
$sql="update user set name=concat(name,'杰伦') where tId='1'";
mysql_query($sql);

$sql="update user set name = '周杰伦' where id='1'";

$sql="update user set name = '周杰伦' where id='1'";

你这个是直接就把name字段修改成"周杰伦"了,
而不是把"杰伦"追加到"周"的后面。
方法不一样,
到实际应用中是不能起到一样的效果的。

那就用concat

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn