更新名称中包含点(.)的MySQL列 [英] Updating a MySQL column that contains dot (.) in its name

查看:92
本文介绍了更新名称中包含点(.)的MySQL列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些列,它们的名称具有结构nameUser.Name,但是在更新它们时遇到了麻烦.我尝试了几种可能性:

I have columns that their names have the structure nameUser.Name, but I'm having trouble updating them. I've tried a few possibilities:

// Ideally, I'd like to do this (since the User.Name is 'dynamic', ie, it depends
// on who is logged in):
$userLogged = 'Some.User';
$columnName = 'name' . $userLogged;
mysql_query("UPDATE Industries SET '$columnName'='$name' WHERE id='$id'");
// Another try:
mysql_query("UPDATE Industries SET $columnName='$name' WHERE id='$id'");
// Alternatively, if the above cannot be achieved:
mysql_query("UPDATE Industries SET 'nameSome.User'='$name' WHERE id='$id'");
// Yet another try:
mysql_query("UPDATE Industries SET nameSome.User='$name' WHERE id='$id'");

但是,以上方法均无效.为什么?

Non of the above works, however. Why?

推荐答案

不要在列名中使用单引号,而应使用反引号(在大多数键盘上,键1的左侧).

Instead of using single-quotes for the column name, use backticks (on most keyboards, to the left of the 1 key).

赞:

mysql_query("UPDATE Industries SET `nameSome.User`='$name' WHERE id='$id'");

这篇关于更新名称中包含点(.)的MySQL列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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