My environment is a Failover ver package,
The code that most frequently appears on the Internet to solve Chinese Garbled text display is:
First: PDO ::__ construct ($ dsn, $ user, $ pass, array
(PDO: MYSQL_ATTR_INIT_COMMAND => "set names 'utf8 ';"));
I tried the first method. The result is that the name field only displays one 'C' character. After that, the Chinese characters are displayed blank.
The result is as follows: 1 shows
I only need to solve this problem: replace UTF8 with GBK directly, that is:
PDO: :__ construct ($ dsn, $ user, $ pass, array (PDO: MYSQL_ATTR_INIT_COMMAND => "SET
NAMES 'gbk ';"));
2 is as follows:
Type 2: PDO ::__ construct ($ dsn, $ user, $ pass );
PDO: exec ("set names 'utf8 ';");
The second type is also tested in my environment. The display effect 1 shows. In this case, replace utf8 with GBK to display
. In addition, Here PDO: $ pdo-> is used in place. Of course, this is a variable, and the variable name can be customized.
Third: $ pdo-> query ('set names utf8 ;');
As for the third type, I have read the above two types. You should also know that you should replace utf8 with GBK, which can also be correctly displayed.
I have tested these methods. Yes. Haha. In addition, I will introduce a method to solve Chinese Garbled text here, but it is similar,
There is nothing to do with the third method, but it doesn't work. This method uses exec instead of query. The Code is as follows:
$ Pdo-> exec ("set character set gbk ");
Haha. I have tried these four methods myself.