Ahm*_*mad 11 php postgresql pdo
我有一个简单的SQL语法插入表.我正在使用Postgresql 8.4并且已经将数据库编码设置为UTF8,并将POSIX设置为Collation和Character类型.
如果我在pgadmin3下运行它,查询就没问题,但如果我在PHP中执行,则会出错.
"Internal Server Error: SQLSTATE[22021]:
Character not in repertoire: 7 ERROR:
invalid byte sequence for encoding \"UTF8\": 0xd85b\nHINT:
This error can also happen if the byte sequence does not match the encoding expected by the server,
which is controlled by \"client_encoding\"
Run Code Online (Sandbox Code Playgroud)
所以我试图从PHP(PDO)设置NAMES和client_encoding,但仍然有同样的问题
$instance->exec("SET client_encoding = 'UTF8';");
$instance->exec("SET NAMES 'UTF8';");
Run Code Online (Sandbox Code Playgroud)
pg_set_client_encoding($link, "UNICODE");
如果我使用本机postgresql驱动程序pg_pconnect
,我的工作,但目前我正在使用PDO作为驱动程序.
我也已经设定好了 mb_internal_encoding('UTF-8');
有没有其他方法可以解决这个问题?
此错误仅在我尝试插入非阿拉伯语或日语单词的非ascii单词时出现
尝试使用utf8_encode()编码为utf-8.
$query = "INSERT INTO student (id, firstName, lastName, age) VALUES (1, 'myFisrtName', 'myLastName', 23)";
pg_exec($connection, utf8_encode($query ));
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
20416 次 |
最近记录: |