使PDO连接utf8编码 [英] Make PDO connection utf8 encoded
本文介绍了使PDO连接utf8编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将我的连接编码为UTF8.我当时在看其他帖子,但因某些原因而无法正常工作.不知道我在做什么错.
I am trying to encode my connection to become UTF8. I was looking at some other posts, but soe some reason it doesnt work. No idea what I am doing wrong.
这是我的conn的样子
$this->db_conn = new PDO("mysql:host=" . $this->host . ";dbname=" . $this->db_name, $this->username, $this->password);
这是我正在尝试做的事情,但它说不正确
$this->db_conn = new PDO("mysql:host=" . $this->host . ";dbname=" . $this->db_name, $this->username, $this->password.";charset=utf8");
给出此错误 数据库连接错误:SQLSTATE [28000] [1045]
Gives this error Database Connection Error: SQLSTATE[28000] [1045] Access denied for
我正在使用MySql
I am using MySql
推荐答案
将字符集移至用户名和密码之前.
Move your charset before the user and password.
$this->db_conn = new PDO("mysql:host=" .
$this->host .
";dbname=" . $this->db_name .
";charset=utf8" ,
$this->username,
$this->password);
这篇关于使PDO连接utf8编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文