0

We started website in intention that we only use English language and do all insertion/deletion to MySQL using English. And use PHP to escape string while writing to database.

Now the situation is our website have lot of Chinese/German/Russian users, and we are facing problem writing data into MySQL - PHP is able to write data to the database but it does some internal conversions like it replace a few characters to something different (eg. Plötzlich --> Plq$tzlich).

But if I go to phpMyAdmin and copy paste Chinese or any other language string and do insert it write exactly as it is. So suspecting is that PHP doing conversion before writing to the database.

We are in process to make it work for all language, but this is first time we are dealing with global languages in (MySQL and PHP).

If any expert could share some info that would be great and highly appreciated.

  1. We have MYSQL InnoDB database with data in it, how shall we do conversion to support global languages?
  2. We use PHP to write records to MySQL and use escape string (data) and then write it to database. We think that escape does not support global languages it does some conversion. How to handle this or what else we should use?
  3. Does this conversion impact existing data in database?

We would be really thankful if we get some expert help on this.

halfer
  • 19,824
  • 17
  • 99
  • 186
SmartDev
  • 481
  • 3
  • 11
  • 30
  • You're using mysqli or PDO? – speccode Nov 05 '13 at 23:53
  • Hi Speccode it is MySQLi – SmartDev Nov 06 '13 at 00:01
  • Can you say more about how you are using PHP to escape data? If you are using MySQLi, you should be using parameterised queries where explicit escaping is not necessary, and should not be done. As for the data corruption, what character set is your database in, and what character set is your web page in? – halfer Nov 06 '13 at 00:49
  • 2
    possible duplicate of [UTF-8 all the way through](http://stackoverflow.com/questions/279170/utf-8-all-the-way-through) <---- this will most likely solve all your problems. – Pekka Nov 06 '13 at 00:58
  • Link provided by @Pekka웃 have a lot information that should help you. Also... I don't know how you escape data but you should do it via prepared statements: http://pl1.php.net/manual/en/mysqli.prepare.php – speccode Nov 06 '13 at 04:57

1 Answers1

0

I would make sure your app is all in UTF-8, including all the db tables. Sounds like some part is not UTF-8.

Who do you escape your text? Maybe something like
http://www.w3schools.com/php/func_string_htmlentities.asp
could help? Where all characters are escaped into html entities.

Remy
  • 12,555
  • 14
  • 64
  • 104