如何在 PHP PgSQL 数据库的 PDO 类构造函数中设置 UTF-8
我想为我的 PDO 对象设置 UTF8.此类与 MySQL 一起正常工作.我找不到 PgSQL 的 array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES UTF8")
类似物,而且我无法使用西里尔符号.
I want to set UTF8 for my PDO object. This class works correctly with MySQL.
I can't find an analog of array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES UTF8")
for PgSQL and I can't work with cyrillic symbols.
class oop{
private $host="localhost";
private $user="xxxx";
private $db="xxxx";
private $pass="111111";
private $conn;
public function __construct(){
$this->conn = new PDO("pgsql:host=".$this->host.";dbname=".$this->db,$this->user,$this->pass,array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES UTF8") );
}
推荐答案
从我在 这个页面,你可以使用以下两个命令之一:
From what I see in section 21.2.3 on this page, you can use one of the following two commands:
将 CLIENT_ENCODING 设置为值";
SET NAMES 'value';
其中值 = UTF8
.尝试使用:
where value = UTF8
. Try using:
SET CLIENT_ENCODING TO 'UTF8';
或
SET NAMES 'UTF8';
相关文章