数据库升级后,MySQL 中的 SELECTing 枚举不起作用,为什么?

发布于 2024-12-04 20:02:32 字数 751 浏览 5 评论 0原文

我目前正在将一个基于 PHP 的大型 Web 应用程序从一台服务器移动到另一台服务器。旧服务器运行 MySQL 5.0.51a(在 SuSE Linux 上),新服务器运行 MySQL 5.5.15(在 ArchLinux 上)。

现在,新的 MySQL 抱怨以下语句(语法错误):

SELECT DISTINCT(field) FROM config WHERE range='global' ORDER BY field

我做了一些测试,发现以下缩短的语句仍然失败(语法错误):

SELECT * FROM config WHERE range='global'

不幸的是,这对我来说看起来是完全合法的 SQL。我的猜测是,它与列 range 的类型有关,即 enum('global', 'user')。从其他列中选择,例如 int 类型的列,效果非常好。

我知道如何在本地解决这个问题,即将列名添加到 where 子句,如下所示:

SELECT * FROM config WHERE config.range='global'

但我不想遍历整个代码,在适当的地方将列名添加到 SQL 语句。


因此我的问题是:

如何告诉 MySQL 5.5.15 接受有点草率的 5.0.51a 语法?

I'm currently moving a large PHP-based webapp from one server to another. The old server is running MySQL 5.0.51a (on SuSE Linux), the new server is running MySQL 5.5.15 (on ArchLinux).

Now, the new MySQL is complaining about the following statement (Syntax Error):

SELECT DISTINCT(field) FROM config WHERE range='global' ORDER BY field

I did a bit of testing and found out that the following shortened statement still fails (with Syntax Error):

SELECT * FROM config WHERE range='global'

Unfortunately, this looks like perfectly legal SQL to me. My guess is that it has to do with the type of column range, which is enum('global', 'user'). Selecting from other columns, e.g. columns of type int, works perfectly fine.

I know how to fix this issue locally, i.e. adding the column name to the where-clause, like this:

SELECT * FROM config WHERE config.range='global'

But I don't want to go through the whole code, adding column names to SQL statements where appropriate.

Hence my question:

How do I tell MySQL 5.5.15 to accept the somewhat sloppy 5.0.51a syntax?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只等公子 2024-12-11 20:02:32

RANGE 是 mysql 5.5 中的保留字 查看列表

保护你的领域,它应该有效:

SELECT * FROM `config` WHERE `range`='global'

RANGE is a reserved word in mysql 5.5 see list

Protect your field, it sould work:

SELECT * FROM `config` WHERE `range`='global'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文