View Full Version : PHP/MySQL character encoding

05-21-2008, 05:13 AM

I'm trying to get UTF-16 characters into my database properly. I think I've narrowed my problem down to my connection between PHP and MySQL. This apostrophe " " is my specific problem, U+ 2019.

I have all of my collations set to ucs2_unicode_ci (table, db connection type and field holding the values).

I can also generate the SQL query from php, save it to a text file, then copy it into PHPMyAdmin and have it run properly.

But still, no matter what I try my apostrophe turns into "’" when it gets to the database.

Thank you for your help.

05-21-2008, 05:26 AM
Ok, so I figured it out 5 minutes after posting. No reason not to share the solution.

All I ended up having to do was use these queries:

mysql_query("SET NAMES 'utf8'");
mysql_query("SET CHARACTER SET 'utf8'");

This is because the connection expects latin1 by default. Basically all these queries are doing is setting these system variables:


I'm assuming you can set these all in your ini file, but if your on shared space (which this particular system is for me) that makes it a bit harder.

So there you go, hope no one got to fired up to solve this one. Hope it helps someone someday.