mysql查询问题

发布于 2024-12-04 03:49:56 字数 592 浏览 0 评论 0原文

我有一个小问题:

我通过 ajax 收到一些参数并进行 sql 查询。简单,但是这个查询有一些特殊字符(巴西),我的查询看起来像这样(因为我做了回显):

SELECT neigh 
FROM address_bd 
WHERE 
  state ="AL" 
  AND city ="Maceió" 
GROUP BY neigh 
ORDER BY neigh ASC

并且在脚本中是:

$sql = "
  SELECT neigh 
  FROM address_bd 
  WHERE state =\"$state\" 
    AND city =\"$city\" 
  GROUP BY neigh 
  ORDER BY neigh ASC
  ";

在 phpmyadmin 中运行它返回正确的结果,但在脚本中给出 0 结果。 我的 sql 行有 utf8_general_ci。有人知道吗?谢谢。

响应如下:

SET character_set_client = utf8;

这解决了这个问题。谢谢大家,特别是 Inca 发送的链接。再次感谢您

I have a small issue:

I recieve few paramaters via ajax and make a sql query. Simple, but this query has some special characters(brazilian) and my query looks like that(as I've made a echo):

SELECT neigh 
FROM address_bd 
WHERE 
  state ="AL" 
  AND city ="Maceió" 
GROUP BY neigh 
ORDER BY neigh ASC

and in the script is:

$sql = "
  SELECT neigh 
  FROM address_bd 
  WHERE state =\"$state\" 
    AND city =\"$city\" 
  GROUP BY neigh 
  ORDER BY neigh ASC
  ";

Running it in phpmyadmin return the correct result, but in the script gives 0 results.
My sql row has utf8_general_ci. Does anyone have any idea? Thank you.

AND here comes the response:

SET character_set_client = utf8;

This resolved the issue. Thank you all and especialy to Inca for sending the link. Thank you again

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

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

发布评论

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

评论(2

九公里浅绿 2024-12-11 03:49:56

您应该将 mysql_set_charset(charset); 或数据库驱动程序的相应操作符放置在数据库连接操作符之后。

charset 应代表 HTML 页面的实际字符集。

you should have mysql_set_charset(charset); or corresponding operator for your database driver placed right after your database connect operator.

and charset should represent actual charset of your HTML pages.

oО清风挽发oО 2024-12-11 03:49:56

也许可以尝试这个:

$sql = "SELECT neigh FROM address_bd WHERE state = '$state' AND city = '$city' GROUP BY neigh ORDER BY neigh ASC";

如果仍然不起作用,请在 mysql_query 函数之后添加此内容

print mysql_error();

,并在此处告诉错误消息内容。

Maybe try this:

$sql = "SELECT neigh FROM address_bd WHERE state = '$state' AND city = '$city' GROUP BY neigh ORDER BY neigh ASC";

If it still does not work add this after mysql_query function

print mysql_error();

and tell here the error message content.

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