Home  >  Article  >  Backend Development  >  PDO Chinese garbled solution_PHP tutorial

PDO Chinese garbled solution_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:38:15918browse

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.

Please indicate the source of bkJia when reprinting http://www.bkjia.com/PHPjc/486504.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/486504.html
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...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn