views:

402

answers:

3

This is what I tried so far,by modifying php.ini: default_charset = "utf-8"

This is how MySQL is configured:

mysql> show variables like '%char%';
+--------------------------+-----------------------------------------------+
| Variable_name            | Value                                         |
+--------------------------+-----------------------------------------------+
| character_set_client     | utf8                                          |
| character_set_connection | utf8                                          |
| character_set_database   | utf8                                          |
| character_set_filesystem | binary                                        |
| character_set_results    | utf8                                          |
| character_set_server     | utf8                                          |
| character_set_system     | utf8                                          |
| character_sets_dir       | f:\wamp\bin\mysql\mysql5.0.45\share\charsets\ |
+--------------------------+-----------------------------------------------+
8 rows in set (0.00 sec)

But it doesn't work.

I've dumped the data,it is in utf-8 format before and after processing by PHP.

But after inserting into MySQL by PHP,

it becomes a big mess(through phpmyadmin),

The data became something like this after inserting into database:

江苏省 江阴市 山观镇 西苑 新村

what's worse,the data become normal again after reading it from MySQL and showing on the page!

Can someone point out what's the real problem here?

The code are all things like:

$dml = "insert into profiles(accountId,name,thumbnail,sex,homeAddr,livingAddr,peoples,married,politicalStatus,qq,mobilePhone,telephone,homePage) 
      value($accountId,'{$_POST['name']}',{$_POST['thumbnail']},{$_POST['sex']},'{$_POST['homeAddr']}','{$_POST['livingAddr']}','{$_POST['peoples']}',{$_POST['married']},'{$_POST['politicalStatus']}',{$_POST['qq']},{$_POST['mobilePhone']},{$_POST['telephone']},{$_POST['homePage']})";
mysql_query($dml,$con);
A: 

Please be more specific about your problem. Post the code that causes the problem, and say something about how it "doesn't work". Without code, we can't solve your problem.

That said, make sure your phpMyAdmin charsets are set appropriately. I think you're trying to say that it looks wrong in phpMyAdmin, in which case that is likely to be where your problem is.

Edit: It's unclear what "what's worse,the data become normal again after reading it from MySQL and showing on the page!" means.

Your comment on the other answer doesn't really prove anything. Just because it looks right in phpMyAdmin doesn't mean it agrees with what's in the database. Your php character set needs to match your database character set needs to match your phpMyAdmin character set. If ANY of them are wrong, you will get EXACTLY this problem. One of them does not match!

Paul McMillan
phpMyAdmin is actually right.
Shore
I've pasted the code here.
Shore
Your pasted code doesn't show us the connection parameters you're using. Make sure php is connecting to your database using UTF-8.
Paul McMillan
How to make sure using UTF-8?All I know about that is configuration in php.ini: default_charset = "utf-8".Is that all?
Shore
Maybe you want this:$con = mysql_connect("localhost:".$LOCAL_DB_PORT, $LOCAL_DB_USER, $LOCAL_DB_PASS);
Shore
+1  A: 

Look at the connection parameters in the php config within phpMyAdmin. When you connect to a database, you can specify an encoding of the connection (as well as all these other places). That could be out of sync causing you problems.

ndp
The connection parameters in the php config within phpMyAdmin should be OK,I can update the tables with utf-8 formatted data.
Shore
See my update,the code is no more than some dml.
Shore
A: 

make sure you HTTP content type is utf-8. that's a tricky one to nail down.

longneck