17

How to configure UTF-8 in the PDO class constructor for the PgSQL PHP database

 3 years ago
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.
neoserver,ios ssh client

How to configure UTF-8 in the PDO class constructor for the PgSQL PHP database

advertisements

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:

  1. SET CLIENT_ENCODING TO 'value';
  2. 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?

I'm creating a simple C# Windows Forms application that connects to a SQL Server database. We have a different server for developing and production, and now I'm changing the IP address of the server directly inside the code. The application is going

How to access a list from a class constructor, for use in another class method, in python?

How do I access a list from a class constructor in python, to use in another class method? For example: Class Data(): def __init__(self): list1 = ["a", "e", "i", "o", "u"] def __length__(): length = len(li

How to configure EmailTraceListener to avoid the overloaded mailbox (on a mass problem)?

How to configure EmailTraceListener to avoid over-flooded mailbox (on mass problem)? Is it possible to setup a maximum for messages sent (per hour/per day) using logging applicaiton block configuration? P.S. I have done it already with some condition

How to configure hadoop replication in the java client by class org.apache.hadoop.conf.Configuration?

I use the java Api as client to upload files ,but it always set the dfs.replication to 3,as a result when I use command (hadoop dfsadmin -report) to check the situation,all blocks are under replication factor,because I just have two data nodes to tes

How to configure IIS so that the user's domain credentials are used when connecting to the SQL Server?

We've recently released the latest version of our intranet application, which now uses windows authentication as standard, and needs to be able to connect to a configured SQL server with the end-user's domain credentials. Lately we've found that on a

How do I migrate from the old PHP database manager library to PDO without breaking code?

I used the AdoDb database handler library for my project, now I want to migrate to PDO but I don't want that whole project stop working what can I do? I used about 10 methods of that handler (and use simple query that work PDO too) so I found two sol

How to configure sqlite to display the default headers

Is there any way to configure sqlite3 so that the headers will display by default? I know I can use ".headers on" to turn on headers, but I have to keep typing it every time I launch the client because the setting doesn't stick between sessions.

How to configure a connection between the iOS device and the server to pass data

I really have no idea about where to start. I need a place to store datas, coming from my application user's but how do i do? The answer is server. I have never had any experience with server side of any application, but now i do but i got no idea ab

How to configure and enable Azure Service Fabric Reverse Proxy for an existing local cluster?

Is the Azure Service Fabric Reverse Proxy available in an on-premises cluster? If so, how can I enable it for an existing cluster? The Service Fabric Reverse Proxy is described here. It allows clients external to the cluster to access application ser

How to configure WordPress FTP plugin downloads with key security for Amazon web services?

I'm trying to set up a WordPress site from an Amazon EC2 instance, and unfortunately I can't seem to get the FTP plugin downloads and so on running because Amazon requires that I use a keypair. What are recommendation for how to configure FTP on Ubun

How to get session data (from the external php script) without being overwritten by Joomla session?

When I include the Joomla framework, the Joomla session seems to be overwriting the session that I am using in another script. How can I get information from the first session AND from Joomla? DETAILS I started a session in a php script external to J

How can I pass one of the many PHP variables I have in JavaScript?

This question already has an answer here: How to pass variables and data from PHP to JavaScript? 17 answers I am currently using AJAX to pass the PHP output to JavaScript, but I want to pass only one of the PHP variables to JavaScript and I don't kno

How can we store data in the local SQLite database with javascript and html5?

Possible Duplicate: How can we store image in html5 sqlite database? How can we store data into local SQLite database with javascript and html5? I do not want the websql I want to save data into the local SQLite database. Is there any example?WebSQL

how to put a link to the message php set

I'm quite new in php and I'm editing code in the cake php. I would like to add a link to the help page after a error message: existing code: if (count($results) > 0) { $this->set("message", "Sorry, that data already exists."); re

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK