

How to configure UTF-8 in the PDO class constructor for the PgSQL PHP database
source link: https://www.codesd.com/item/how-to-configure-utf-8-in-the-pdo-class-constructor-for-the-pgsql-php-database.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How to configure UTF-8 in the PDO class constructor for the PgSQL PHP database
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:
SET CLIENT_ENCODING TO 'value';
SET NAMES 'value';
where value = UTF8
. Try using:
SET CLIENT_ENCODING TO 'UTF8';
SET NAMES 'UTF8';
Related Articles
How to configure a connection to the C # application database easily for development and production without changing code and recompilation?
How to access a list from a class constructor, for use in another class method, in python?
How to configure EmailTraceListener to avoid the overloaded mailbox (on a mass problem)?
How to configure hadoop replication in the java client by class org.apache.hadoop.conf.Configuration?
How to configure IIS so that the user's domain credentials are used when connecting to the SQL Server?
How do I migrate from the old PHP database manager library to PDO without breaking code?
How to configure sqlite to display the default headers
How to configure a connection between the iOS device and the server to pass data
How to configure and enable Azure Service Fabric Reverse Proxy for an existing local cluster?
How to configure WordPress FTP plugin downloads with key security for Amazon web services?
How to get session data (from the external php script) without being overwritten by Joomla session?
How can I pass one of the many PHP variables I have in JavaScript?
How can we store data in the local SQLite database with javascript and html5?
how to put a link to the message php set
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK