There is a table in which records are stored in Russian. The character sets for the columns are different (utf8_unicode_ci, cp1251_general_ci, utf8_general_ci, utf8_bin). After connecting to the database I prescribe:

mysql_query("SET NAMES cp1251"); 

In the output, all values ​​where there were Russian words (independent of the encoding) are null. If you do not register, then in the output instead of Russian letters are question marks. How to fix it? PS Table encoding utf8_general_ci. The browser coding tried to install on both cp1251 and utf8 , did not help.

  • is it like php? if so then the encoding should be UTF-8. Try it anyway. by the way, if php is really then mysql is out of date you need at least mysqli - barmaglott
  • Is the output not being filtered? For example, the htmlspecialchars () function? Try writing a simple script that prints unfiltered data from the table. Since the installation of the connection encoding should lead to the fact that MySQL should correctly process your data, receiving and sending it to Windows-1251, and storing it in tables in exactly those encodings that you specified. - cheops

1 answer 1

If instead of Russian values ​​you get blank lines, you are very likely to filter the text using the htmlspecialchars() function. The third parameter of this function allows you to set the text encoding. Unfortunately, in the latest versions of PHP, the perfect chehord was working with him. At first, it was set by default in ISO encoding, so without explicitly specifying the encoding, an empty string could be obtained, then the ISO encoding was changed to UTF-8, now the default encoding is set using the default_charset directive from the php.ini configuration file.

Depending on the PHP version, you can get into a situation where the Russian text, even in UTF8, will not be displayed by default using htmlspecialchars() . In this case, set the default_charset directive to UTF8

 default_charset = "UTF-8" 

If this does not help, set the string "UTF-8" as the third parameter to the htmlspecialchars() function.

 echo htmlspecialchars($str, ENT_NOQUOTES, "UTF-8");