pdo连接aws-rds字符集

djmepvbi  于 2021-06-15  发布在  Mysql
关注(0)|答案(1)|浏览(344)

当试图通过pdo连接到aws rds数据库时,我得到

"Erreur : SQLSTATE[HY000] [2054] Server sent charset unknown to the client"

我在某个地方读到,我可以尝试更改我的.cnf文件。
我没有找到一个,所以在applications/mamp/conf中创建了它

[client]
default-character-set=utf8

[mysql]
default-character-set=utf8

[mysqld]
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8

但还是不行(我正在用mapmp和php7.0.15开发mac)谢谢!

dhxwm5r4

dhxwm5r41#

字符集应该是-
pdo::mysql\u attr\u init\u command=>“设置名称utf8”
下面是示例pdo连接代码-

$host = "asjhdkjashdkj.asjdhaskd.ap-southeast-1.rds.amazonaws.com";
$username = "user";
$password = "pass";
$db_name = "database";
return new PDO('mysql:host=' . $host . ';dbname=' . $db_name, $username, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));

相关问题