UTF-8 的外键约束
我最近将数据库转换为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能是需要正确设置客户端编码的情况。在初始 mysql 连接后尝试此操作:
This may be a case of needing client encoding set properly. Try this after the initial mysql connect: