How set UTF-8 in PDO class constructor for PHP PgSQL database

后端 未结 3 621
栀梦
栀梦 2020-12-09 20:31

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

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-09 21:10

    it is very easy to find an analog for the regular SQL query

    $pdo->query("SET NAMES UTF8")
    

    However, encoding have to be set in DSN anyway

    $this->conn = new PDO("pgsql:host=".$this->host.";dbname=".$this->db.";charset=".$this->charset
    

提交回复
热议问题