pg_set_client_encoding

(PHP 4 >= 4.0.3, PHP 5, PHP 7, PHP 8)

pg_set_client_encoding 设定客户端编码

说明

pg_set_client_encoding(PgSql\Connection $connection = ?, string $encoding): int

pg_set_client_encoding() 设定客户端编码,成功返回 0,出错返回 -1。

PostgreSQL 会自动将后端数据库编码中的数据转换成前端编码。

注意:

本函数以前的名字为 pg_setclientencoding()

参数

connection

An PgSql\Connection instance. When connection is unspecified, the default connection is used. The default connection is the last connection made by pg_connect() or pg_pconnect().

警告

As of PHP 8.1.0, using the default connection is deprecated.

encoding

必需的客户端编码。SQL_ASCIIEUC_JPEUC_CNEUC_KREUC_TWUNICODEMULE_INTERNALLATINX (X=1...9)、KOI8WINALTSJISBIG5WIN1250 中的一个。

确切有效的编码列表取决于 PostgreSQL 版本,因此查阅 PostgreSQL 手册获取更具体的列表。

返回值

成功时返回 0 失败时返回 -1

更新日志

版本 说明
8.1.0 现在 connection 参数接受 PgSql\Connection 实例,之前接受 resource

示例

示例 #1 pg_set_client_encoding() 示例

<?php

$conn
= pg_pconnect("dbname=publisher");
if (!
$conn) {
echo
"An error occurred.\n";
exit;
}

// Set the client encoding to UNICODE. Data will be automatically
// converted from the backend encoding to the frontend.
pg_set_client_encoding($conn, "UNICODE");

$result = pg_query($conn, "SELECT author, email FROM authors");
if (!
$result) {
echo
"An error occurred.\n";
exit;
}

// Write out UTF-8 data
while ($row = pg_fetch_row($result)) {
echo
"Author: $row[0] E-mail: $row[1]";
echo
"<br />\n";
}

?>

参见

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top