MySQL LIKE 表达式中的连字符

发布于 2024-11-16 16:10:00 字数 643 浏览 1 评论 0原文

我正在使用一个遗留的 PHP 框架,并且遇到了一些我无法追踪的奇怪行为。

我正在运行一个看起来像这样的查询

select * from table where column like '%word-anotherword%'

,我想从表中返回记录,其中列包含文本“word-anotherword”。 (列是长文本字段)。

当我在 phpMyAdmin 中运行此查询时,我得到了预期的结果。但是当我从我们的框架内部运行它时,我没有得到任何结果。我已在单独的 .php 文件中运行它,使用 mysql_link 、 mysql_query 来运行查询,并且其行为也符合预期。

当我在框架中直接回显查询并将其传递给 mysql_query 时,它的格式与我预期的完全一样。 IE 我们的框架并没有以某种意想不到的方式逃避它。

我假设我们的框架在某个地方覆盖了某些 PHP 设置,从而导致了这种行为差异,但我没有运气用谷歌搜索它可能是什么。我发现这篇文章,这似乎是一个好的开始,但也没有'似乎不太符合我所看到的,因为我在相同的 MySQL 设置上得到了不同的行为。

任何正确方向的指示将不胜感激!

I am working with a legacy PHP framework and am coming across some strange behavior that I can't track down.

I'm running a query that looks something like this

select * from table where column like '%word-anotherword%'

, which I would like to return records from table where column contains the text "word-anotherword". (column is a longtext field).

When I run this query in phpMyAdmin, I get the expected results. But when I run it from inside our framework, I get no results. I have run it in a separate .php file, using mysql_link, mysql_query to run the query, and that also behaves as expected.

When I echo out the query in the framework directly before it is passed to mysql_query, it is formatted just the same as I expect. I.E. our framework is not escaping it in some unexpected manner.

I am assuming that our framework is overriding some PHP setting somewhere to cause this difference in behavior, but I have had no luck googling for what it might be. I found this article, which seemed to be a good start, but also didn't quite seem to fit what I'm seeing, since I am getting different behaviors on the same MySQL setup.

Any pointers in the right direction would be greatly appreciated!

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

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

发布评论

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

评论(2

惜醉颜 2024-11-23 16:10:00

作为调试注意事项:

当您echo查询时,您可能需要确保您确实看到了数据 - 例如,如果您echo-ing到网页上,请确保将 htmlspecialchars() 应用于字符串。否则你可能不会发现一些变化。

As a debugging heads-up:

When you echo your query out, you might want to make sure you're actually seeing the data - e.g. if you're echo-ing onto a webpage, make sure you're applying htmlspecialchars() to the string. Otherwise you might not spot some changes.

迷爱 2024-11-23 16:10:00

LIKE 不是全文搜索,这就是问题标题错误的原因,并且您找到的那篇文章可能与您的问题无关。

关于您的问题,请打开 my.cnf 并启用查询日志:

[mysqld]

#Set General Log
log = "C:/all_queries.log"

现在运行您的查询并查看日志。

LIKE is not full text search, that's why question title is wrong and, probably, that article which you found isn't related to your problem.

And about your problem, open your my.cnf and enable queries log:

[mysqld]

#Set General Log
log = "C:/all_queries.log"

Now run your query and look into log.

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