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);
share|improve this question
Is phpMyAdmin configured to use the correct character set? – shadowhand Sep 3 '09 at 0:54

3 Answers

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.

share|improve this answer
The connection parameters in the php config within phpMyAdmin should be OK,I can update the tables with utf-8 formatted data. – omg Sep 3 '09 at 0:58
See my update,the code is no more than some dml. – omg Sep 3 '09 at 1:08

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!

share|improve this answer
phpMyAdmin is actually right. – omg Sep 3 '09 at 0:59
I've pasted the code here. – omg Sep 3 '09 at 1:07
1  
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 Sep 3 '09 at 1:10
How to make sure using UTF-8?All I know about that is configuration in php.ini: default_charset = "utf-8". Is that all? – omg Sep 3 '09 at 1:19
Maybe you want this: $con = mysql_connect("localhost:".$LOCAL_DB_PORT, $LOCAL_DB_USER, $LOCAL_DB_PASS); – omg Sep 3 '09 at 1:22

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.