This status is stored in the current state in the database (although Денис should be written).

The table setting is specified as utf8_unicode_ci . In the PHP code settings also

 mysqli_query("SET NAMES utf8") mysqli_query("SET CHARACTER SET utf8"); 

When outputting from a database to an HTML page, the data is displayed correctly. Why is the database incorrectly displayed via phpMyAdmin also via the console, a solid kryakozyabrin

enter image description here

  • And there’s still such magic, if I take a message from a contact, say, written in Russian, insert a script into the database via php, it is displayed correctly, but if I do this through Ubuntu with my own handles, I write a Russian inscription on my keyboard with my own handles, then again wonderful kryakozyabry. - Slayzz 2:58 pm
  • Total helped. Paste the code mysqli_set_charset ($ dbc, "utf8") into php; - Slayzz

4 answers 4

Why is the database incorrectly displayed via phpMyAdmin also via the console, a solid kryakozyabrin.

Because the tables contain the data in utf8 , while the table definition contains the default latin1 . You can verify this by entering the command

 SHOW CREATE TABLE MyGuests; 

When phpMyAdmin tries to work correctly by requesting data from the database in the encoding in which it is going to output them, the database tries to transcode the Russian text from latin1 to utf8, and we get Ð”ÐµÐ½Ð¸Ñ .

The wrong solution with skip-character-set-client-handshake outputs the data as is, without re-encoding it. But this, of course, is a crook of the curve. At the first attempt to search data or sort it, the results will be VERY surprising.

It is necessary to set the tables adequate encoding. If the database is not yet live, then delete the tables, set the default encoding for the database,

 ALTER DATABASE aliendatabase CHARACTER SET utf8; 

re-create tables and start work from scratch. Simply changing the encoding "in the forehead", making the alter table does not work out - after this command, mysql faithfully recodes the underlying data into the form Ð”ÐµÐ½Ð¸Ñ , just like it does now when it is issued, but for good .

If the base is "live", you can use the instructions , but before that you must make a backup.

  • Thanks, enormous, everything is accessible and understandable. Earned after removing the table and creating a database from scratch, indicating the encoding in utf8. Then the question arises, how to specify in the mysql config so that when creating a database or a table, the default encoding is set to UTF8. [client] default-character-set = utf8 [mysql] default-character-set = utf8 [mysqld] character_set_server = utf8 collation_server = utf8_general_ci init-connect = 'SET NAMES - Slayzz
  • There was also another question, how to add the ability to write in the mysql client in the terminal in Russian. For clarification, I can write in a clean terminal in Russian encoding, but in the client mysql can not, how to add a sort of opportunity? - Slayzz 1:21 pm
  • It helped, but only if the pens are inserted into mysql, via phpadmin, but if through the php script, then unfortunately everything is also all the same nano-hacking kryakozyabry ... - Slayzz

Encoding when inserted must also be UTF-8. Probably the php file encoding is not UTF-8.

  • The encoding of the php file itself, also UTF-8, is all in this encoding, and the table in the database, and the database itself, tried everything, and when outputting in php code, on the page itself also issues in UTF-8, if written directly through the console Russian characters, then normally displayed. For some reason through the php script. I tried everything, changed the encoding of the database, the tables to UTF-8, saved the script in the same encoding, anyway the crackers ... - Slayzz

Solved the problem in this way. I added the following line to my.cnf config:

 skip-character-set-client-handshake 

If there are better options, then I am ready to listen.

    I was helped by putting the encoding after the connection.

     mysqli_set_charset($your_db_connection, 'utf8'); 

    Do not scold, I know that mysqli is not used for a long time :)

    An example of how to set the encoding for pdo

    First option:

     new PDO("mysql:host=localhost;dbname=$DB_NAME;charset=utf8;", $DB_USER, $DB_PASS); 

    The second option is how to assign the use of UTF-8 by default in MySQL:

     new PDO("mysql:host=localhost;dbname=$DB_NAME;", $DB_USER, $DB_PASS, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));