How to keep character encoding with database queries.

Posted by JasonS on Stack Overflow See other posts from Stack Overflow or by JasonS
Published on 2010-04-13T10:09:57Z Indexed on 2010/04/13 10:12 UTC
Read the original article Hit count: 506

Filed under:
|
|

Hi,

I am doing the following.

1) I am exporting a database and saving it to a file called dump.sql. 2) The file is then transferred to a different server via PHP ftp. 3) When the file has been successfully transferred the administrator has an option to run a 'dbtransfer' script on the new host. 4) This script blows up the script and runs the queries line by line.

This works great - however there is a problem with foreign language encoding. We are using UTF-8.

Step 1 : This works fine, file is in UTF-8 Format. Step 3 : When I test the contents of the dump.sql file using mb_check_encoding(). The string comes back as UTF-8. Step 4 : This creates tables with utf8_general_ci encoding. The information is dumped in.

When I check the table after the transfer I get records like this: 'ç,Ç,ö,Ö,ü,Ü,ı,İ,ş,Ş,ğ,Ğ'. I don't understand how a UTF-8 string can lose its encoding when it goes into the database. Am I missing a step? Do I need to run some sort of function to ensure the string is parsed as UTF-8?

Once the system is installed I can save foreign language queries. It is just the transfer that is messing up.

Any ideas?

© Stack Overflow or respective owner

Related posts about php

Related posts about encoding