Home php Installing the encoding in UTF-8 for the current compound with MySQL

Installing the encoding in UTF-8 for the current compound with MySQL [Duplicate]




Good day.

The result of the SQL query is not returned to UTF-8 encoding. I tried to set the encoding using the mysql_set_charset function ('utf8', $ db) , but all visibility does not work the function, despite the fact that MySQL version 5.0.7. As you can set the connection encoding otherwise, but not using Set Names ?

z. When it worked with the same table using PDO , when installing encoding:

$ db- & gt; exec ('set character set utf8')

Fields returned to UTF-8 .

Answer 1, Authority 100%

The most 100% code for 100% UTF-8: D

mysql_query ("set names 'utf8'");
mysql_query ("SET CHARACTER SET 'UTF8'");

Answer 2, Authority 75%

  1. Original MySQL API (MySQL _ functions) are outdated, starting with PHP 5.5.0, and removed in PHP 7.0.0.
  2. For an improved mouse mysql (MySQL IMPROVED), the preferred method is the use of the set_charset () .

    $ mysqli- & gt; set_charset ('UTF8');


    mysqli_set_charset ($ Link, 'UTF8');

    Use for this purpose Query () (for example: Set Names 'UTF8' ) not recommended .

  3. In PDO, you should specify the connection encoding in the DSN parameter when creating an instance of the database class instance:

    $ dsn = 'mysql: dbname = db; host = host; charset = utf8';
    $ PDO = New \ PDO ($ DSN, $ User, $ Password, $ Options);

p.s. To work with four-clickable UTF-8 (for example, the emoji is saved to the database) instead of the utf8 encoding, use the UTF8MB4 encoding. The base must also be configured using UTF8MB4.

Answer 3, Authority 17%

set names 'utf-8'

Answer 4, Authority 17%

If the problem with the non-Names UTF8 function) on the local Denwer web server is due to the fact that the CP1251 encoding is assigned to the default parameters – the head of the head broke.

Answer 5, Authority 8%

mysql_query ('set Names utf8 collate utf8_general_ci');

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions