我正在尝试将我的连接编码为UTF8。我当时在看其他帖子,但由于某种原因它不起作用。不知道我在做什么错。
这是我的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]
的访问被拒绝我正在使用MySql
答案 0 :(得分:1)
它必须是第一个参数的一部分。您的第二个版本应如下所示:
$this->db_conn = new PDO("mysql:host=" . $this->host . ";dbname=" . $this->db_name.";charset=utf8", $this->username, $this->password);
您得到的错误是因为您的密码错误(您在密码后附加了“; charset = utf8”,并且密码可能不会以此结尾)。
答案 1 :(得分:1)
将字符集移到用户名和密码之前。
CourseId