Home > Backend Development > PHP Tutorial > PDO Chinese garbled solution_PHP tutorial

PDO Chinese garbled solution_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 17:38:15
Original
1026 people have browsed it

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 of this Website
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
Latest Issues
Database pdo connection problem
From 1970-01-01 08:00:00
0
0
0
pdo installation
From 1970-01-01 08:00:00
0
0
0
$pdo->exec($sql);Why does it always return false?
From 1970-01-01 08:00:00
0
0
0
PHP PDO predefined constants
From 1970-01-01 08:00:00
0
0
0
PDO query data error
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template