mysql查询问题
我有一个小问题:
我通过 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该将
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.也许可以尝试这个:
如果仍然不起作用,请在 mysql_query 函数之后添加此内容
,并在此处告诉错误消息内容。
Maybe try this:
If it still does not work add this after mysql_query function
and tell here the error message content.