UTF-8 的外键约束

发布于 2024-11-09 09:41:37 字数 607 浏览 4 评论 0原文

我最近将数据库转换为 UTF-8,本来就应该是这样。一切看起来都很好,除了当我使用该函数时,

echo mb_detect_encoding($_POST['province']);

我为所有不包含特殊字符的内容获取 ASCII,并且为包含特殊字符的所有内容获取 UTF-8。然而,这些值都是从数据库本身中提取的,所以这让我感到困惑。这是它应该如何工作的吗?

另一件不起作用的事情是我的外键约束;我无法从下拉列表中输入值,这又从数据库中提取值,所以。

当我使用时,

echo mb_detect_encoding($_POST['province']);
echo $_POST['province'];

UTF-8
Galápagos

由于省份表上的外键限制,我无法进入报告表下的数据库 但是,该值直接来自省份表。我在这里失去了理智。

但是,我得到了

ASCII
Carchi

厄瓜多尔的另一个省份,该值直接进入数据库。我在这里做错了什么?

I recently converted my database to UTF-8, which it should have been in the first place. Everything looks fine, except when I use the function

echo mb_detect_encoding($_POST['province']);

I am getting ASCII for everything that doesn't contain special characters, and I am getting UTF-8 for everything that does. However, these values are all being pulled from the database itself, so this is confusing to me. Is this how it is supposed to work?

Another thing that is not working is my foreign key constraint; I am unable to enter values from a dropdown list, which is again pulling the values from the database, so.

When I use

echo mb_detect_encoding($_POST['province']);
echo $_POST['province'];

I get

UTF-8
Galápagos

Which I cannot enter into the database under the reports table due to the foreign key restraint on the province table. However, the value coming directly from province table. I am losing my mind here.

However, I get

ASCII
Carchi

For another province in Ecuador, and this value goes right into the database. What am I doing wrong here?

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

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

发布评论

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

评论(1

爱你不解释 2024-11-16 09:41:37

这可能是需要正确设置客户端编码的情况。在初始 mysql 连接后尝试此操作:

mysql_query("SET NAMES 'utf8'")

This may be a case of needing client encoding set properly. Try this after the initial mysql connect:

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