Quickly switched from Windows to Linux (Kubuntu). Put PHP, MySQL and Apache 2 (all from the repository). In MySQL, all character-set- * changed to utf8, except for character-set-filesystem - there is a binary left. And it turned out that if in the file (by the way all the files in utf8) write php code that pushes specific string constants into the databases, then everything is displayed on the page as needed. If in MySQL you need to fill in the database from the sql file, then on the page there are question marks (and the number of question marks is clear, the number of letters). Do not tell me what the snag is and where to look.

PS again emphasize that all files in utf8. And here are the variables from MySQL:

| 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 

UPD
It is very strange that the data inserted via php in the terminal is displayed as krakozabrami (one character - two), but this is all good in the browser. And the data inserted through source filename.sql or through mysql -u = user --password = password <filename.sql in the terminal is displayed normally. And in the browser is familiar? at the same time the number of question marks exactly (!) acc. number of characters.

  • Did the field and table encodings be checked? - Dex
  • "And the encoding of fields and tables checked?" You about it CREATE TABLE _____ (...) DEFAULT CHARSET = utf8 DEFAULT COLLATE utf8_unicode_ci; ? - DUP

4 answers 4

The dump of the database itself when creating tables makes them cp1251. There are two mysql_set_charset("utf8") out: either to fix the database dump, or to explain PHP that the database is in cp1251 using the mysql_set_charset("utf8") directive immediately after mysql_connect

  • The SQL file is handwritten, it is in uft-8. - DUP

Generally it is better to use mysql_query('SET NAMES UTF8'); what they wrote more than once. If there are problems with the dump, I think it is worth changing the encoding of the file itself. As far as I remember the text editor allows it.

  • This is not a dump, but a manually written file. He is in utf8. mysql_query ('SET NAMES UTF8') is added both in the configuration file and in the sql file itself - DUP

Most likely you have default_charset - cp1251 and in the query, when creating tables, you probably do not specify the encoding, so exit 2 - go under the root and change the default_charset in the config, or specify the encodings in the SQL query.


Oh gods, I seem to understand: D

Add to the page in which display either:

  header("Content-Type:text/html; charset=UTF-8"); 

Or in the head page:

  <meta charset="utf-8"> <!--или--> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
  • default_charset is utf8. Why change something in the requests. If the site worked under windows, and continues to work fine on a hosting for Linux. I just need it to work on my local machine. - DUP
  • Well, miracles do not happen. Change because, according to your description of the problem, I did not find another explanation, apparently. Well, ok, I’ll be waiting for the solution to your problem, I’m really wondering what it’s like (vryatli you post it because most likely the problem is something very simple that you have missed (and) or don’t know) - Zowie
  • I understand that the shortcoming on my part. Therefore, I ask. It is very strange that the data inserted via php in the terminal is displayed as krakozabrami (one character - two), but this is all good in the browser. And the data inserted through source filename.sql or through mysql -u = user --password = password <filename.sql in the terminal is displayed normally. And in the browser is familiar? at the same time the number of question marks exactly (!) acc. number of characters. - DUP
  • On the page, and so there is <meta charset = "utf-8"> on it Utf8 is well displayed not from the base. I repeat once again that everything works on windows and on a Linux host, so you need to look for the trail in the php / apache / mysql setting - DUP
  • Well ... you describe the magic - there are tables in utf-8, there are set names utf8, a description of the site coding ... There are no miracles, look for - Zowie

If interested, then everything is “fixed” by deleting the line
SET NAMES utf8

At the beginning of the sql file. I wonder why this is so.