MySQL, PHP, JavaScript UTF-8 Problem with swedish

2019-09-15 01:03发布

问题:

Okay, so I know this has been discussed millions of times. And I've seen billions of attempts to solve the problem. And in most cases they have. But in my case, something still doesn't want to work.

I have ALL my files encoded with utf-8 (none missed, controlled several times). And I have my whole database, tables and everything encoded as utf8_general_ci (have tried utf8_unicode_ci and utf8_bin without result). But still I just get the "?-cube" everywhere instead of my swedish letters.

I've made some tests and have come to the conclusion that it's the jquery load and post calls that's responsible for the problem. If i load my php-file "load-folders.php" i get the correct åäöÅÄÖ. But even though the main file "index.php" is saved as AND has enctype utf8 when it calls the jquery load('load-folders.php') i still get the faulty letters. And yes, the jquery.js is also utf-8. So is my stylesheets and everything. I really don't get it. Is there anything else that might cause a problem when using javascript jquery to load a file into another. The standard is supposed to be utf-8 so it should work.

Anyone out the who is able to help me - I love you.

Thanks in advance!

回答1:

I had a problem exactly like this. The only think that worked was:

mysql_query("SET NAMES utf8"); 

Write it just before your mysql query, like this:

mysql_query("SET NAMES utf8"); 
$q = mysql_query("SELECT * FROM ...") or die('Error: ' . mysql_error());

You can read comments over here: http://php.net/manual/en/function.mysql-client-encoding.php