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'");
mysql_query ("SET SESSION COLLATION_CONNECTION = 'UTF8_GENERAL_CI");
Answer 2, Authority 75%
- Original MySQL API (
MySQL _
functions) are outdated, starting with PHP 5.5.0, and removed in PHP 7.0.0. -
For an improved mouse mysql (MySQL IMPROVED), the preferred method is the use of the set_charset () .
... $ mysqli- & gt; set_charset ('UTF8'); ...
or
... mysqli_set_charset ($ Link, 'UTF8'); ...
Use for this purpose Query () (for example:
Set Names 'UTF8'
) not recommended . -
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');