Home > Article > Backend Development > PDO Chinese garbled solution_PHP tutorial
PDO class, it is found that there will also be UTF-8 garbled problem, the following solution:
<font face="NSimsun">// Method 1:<code><font face="NSimsun">// 方法一:<br>
PDO::__construct($dsn, $user, $pass, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8;"));<br>
<br>
// 方法二:<br>
PDO::__construct($dsn, $user, $pass);<br>
PDO::exec("SET NAMES utf8;");</font>
PDO::__construct($dsn, $user, $pass, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8;"));
//Method 2:
PDO::__construct($dsn, $user, $pass);PDO::exec("SET NAMES utf8;");
Both methods can solve the problem. The principles are the same. Which one you use depends on your preference.TechArticlePDO class, it is found that there will also be UTF-8 garbled problem, the following solution: // Method 1: PDO: :__construct($dsn, $user, $pass, array(PDO::MYSQL_ATTR_INIT_COMMAND = SET NAMES utf8;)); // Method 2...