Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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") );

}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.3k views
Welcome To Ask or Share your Answers For Others

1 Answer

Let me point out the comment by xmedeko, that is absolute right:

pg_connect("host=localhost options='--client_encoding=UTF8'");

Source: http://php.net/manual/en/function.pg-connect.php

Using charset=utf8 is working (only) with mysql...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...