使用concat的pdo更新语句不起作用 [英] pdo update statement using concat is not working

查看:46
本文介绍了使用concat的pdo更新语句不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对PDO还是陌生的,并且无法使下面的更新语句起作用.我希望能够通过仅用逗号和新名称附加到当前值来更新名称字段.结果名称字段应为james,doug,paul等.这可能是一个简单的答案,但我无法通过大量谷歌搜索找到解决方案!

I am still new to PDO and am having trouble getting the update statement below to work. I want to be able to update the name field by just appending to the current value with a comma and the new name. Resulting name field should be like james,doug,paul,etc. This is probably a simple answer but I haven't been able to find a solution through a lot of googling!

预先感谢

    $stmt = $db->prepare('UPDATE table SET name = concat(name, ',' :name) WHERE id = :id');
    $stmt->execute( array('name' => $name, 'id' => $id) );

推荐答案

您在concat中缺少逗号.

you lack comma inside your concat.

 $stmt = $db->prepare("UPDATE table SET name = concat(name, ',', :name) WHERE id = :id");
                      ^                                        ^ here                 ^

这篇关于使用concat的pdo更新语句不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆