Foreign key constraint with UTF-8
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 provi开发者_如何学Pythonnce 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?
This may be a case of needing client encoding set properly. Try this after the initial mysql connect:
mysql_query("SET NAMES 'utf8'")
精彩评论